Skip to content

Commit

Permalink
fix(ImageCropper): Add dom ids to picture crop fields
Browse files Browse the repository at this point in the history
These DOM ids have been removed in cb49ce8
to remove duplicated DOM ids.

But we need DOM ids for the image cropper
to work.

Fixed by adding unique DOM ids for these fields.

Closes #2216
  • Loading branch information
tvdeyen committed Nov 23, 2021
1 parent 32c7a1e commit d629309
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/views/alchemy/ingredients/_picture_editor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<%= f.hidden_field :link_title, data: { link_title: true }, id: nil %>
<%= f.hidden_field :link_class_name, data: { link_class: true }, id: nil %>
<%= f.hidden_field :link_target, data: { link_target: true }, id: nil %>
<%= f.hidden_field :crop_from, data: { crop_from: true }, id: nil %>
<%= f.hidden_field :crop_size, data: { crop_size: true }, id: nil %>
<%= f.hidden_field :crop_from, data: { crop_from: true }, id: picture_editor.form_field_id(:crop_from) %>
<%= f.hidden_field :crop_size, data: { crop_size: true }, id: picture_editor.form_field_id(:crop_size) %>
<% end %>
<% end %>
11 changes: 10 additions & 1 deletion spec/views/alchemy/ingredients/picture_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:picture) { stub_model(Alchemy::Picture) }
let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat_ingredients") }
let(:element_editor) { Alchemy::ElementEditor.new(element) }
let(:ingredient_editor) { Alchemy::IngredientEditor.new(ingredient) }

let(:ingredient) do
stub_model(
Expand All @@ -22,7 +23,7 @@
it_behaves_like "an alchemy ingredient editor"

before do
allow(element_editor).to receive(:ingredients) { [Alchemy::IngredientEditor.new(ingredient)] }
allow(element_editor).to receive(:ingredients) { [ingredient_editor] }
allow(ingredient).to receive(:settings) { settings }
view.class.send :include, Alchemy::Admin::BaseHelper
view.class.send :include, Alchemy::Admin::IngredientsHelper
Expand Down Expand Up @@ -66,6 +67,14 @@
it "shows cropping link" do
is_expected.to have_selector('a[href*="crop"]')
end

it "has crop_from hidden field" do
is_expected.to have_selector("input[type=\"hidden\"][id=\"#{ingredient_editor.form_field_id(:crop_from)}\"]")
end

it "has crop_size hidden field" do
is_expected.to have_selector("input[type=\"hidden\"][id=\"#{ingredient_editor.form_field_id(:crop_size)}\"]")
end
end

context "with image cropping disabled" do
Expand Down

0 comments on commit d629309

Please sign in to comment.