Skip to content

Commit

Permalink
replace link_to_add_fields usage and deprecate helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
hefan committed Mar 13, 2020
1 parent dd62a3b commit 95d750a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions backend/app/helpers/spree/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def link_to_add_fields(name, target, options = {})
css_classes = options[:class] ? options[:class] + " spree_add_fields" : "spree_add_fields"
link_to_with_icon('plus', name, 'javascript:', data: { target: target }, class: css_classes)
end
deprecate link_to_add_fields: "Please use button_tag instead, Example: \n" \
"button_tag \"Name\", type: \"button\", data: { target: \"tbody#div\" }", deprecator: Spree::Deprecation

# renders hidden field and link to remove record using nested_attributes
def link_to_remove_fields(name, form, options = {})
Expand Down
4 changes: 3 additions & 1 deletion backend/app/views/spree/admin/option_types/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<% content_for :page_actions do %>
<li>
<span id="new_add_option_value" data-hook>
<%= link_to_add_fields t('spree.add_option_value'), "tbody#option_values", class: 'btn btn-primary' %>
<%= button_tag t('spree.add_option_value'), type: 'button',
data: { target: 'tbody#option_values' },
class: 'btn btn-primary spree_add_fields' %>
</span>
</li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<% if can?(:create, Spree::ProductProperty) %>
<ul class="tollbar inline-menu">
<li>
<%= link_to_add_fields t('spree.add_product_properties'), 'tbody#product_properties', class: 'plus btn btn-primary' %>
<%= button_tag t('spree.add_product_properties'), type: 'button',
data: { target: 'tbody#product_properties' },
class: 'btn btn-primary spree_add_fields' %>
</li>
</ul>
<% end %>
Expand Down Expand Up @@ -55,7 +57,9 @@
<div class="form-buttons filter-actions actions">
<%= button_tag t('spree.filter_results'), class: 'btn btn-primary' %>
<% if @option_value_ids.present? %>
<%= link_to_add_fields t('spree.add_variant_properties'), 'tbody#variant_property_values', class: 'plus button' %>
<%= button_tag t('spree.add_variant_properties'), type: 'button',
data: { target: 'tbody#variant_property_values' },
class: 'button spree_add_fields' %>
<% end %>
</div>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/products/option_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
expect(page).to have_css("tbody#option_values tr", count: 1)

# Add a new option type
click_link "Add Option Value"
click_button "Add Option Value"
expect(page).to have_css("tbody#option_values tr", count: 2)

# Remove default option type
Expand Down

0 comments on commit 95d750a

Please sign in to comment.