mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Use built-in feature to delete new record row
I looked at the source code and found that we were missing one detail: data-new-record. https://github.com/stimulus-components/stimulus-rails-nested-form/blob/master/src/index.ts#L32-L35 It's documented here, but it's easy to miss: https://www.stimulus-components.com/docs/stimulus-rails-nested-form/
This commit is contained in:
@@ -76,8 +76,8 @@
|
||||
|
||||
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", product.variants.build) do |new_variant_form|
|
||||
%template{ 'data-nested-form-target': "template" }
|
||||
%tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper" }
|
||||
= render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options: }
|
||||
%tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': "true" }
|
||||
= render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options: }
|
||||
|
||||
%tr{ 'data-nested-form-target': "target" }
|
||||
%tr.condensed
|
||||
|
||||
@@ -118,11 +118,6 @@ export default class BulkFormController extends Controller {
|
||||
this.recordElements[recordId]
|
||||
.splice(elmntsToDelete[0], elmntsToDelete[elmntsToDelete.length - 1] - elmntsToDelete[0] + 1);
|
||||
this.toggleFormChanged();
|
||||
|
||||
// Otherwise, elements within tr may be re-added to recordElements.
|
||||
// With the nested-form-wrapper(stimulus components) class added to a tr.
|
||||
let tr = document.querySelector('.nested-form-wrapper[style="display: none;"]')
|
||||
tr.remove();
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
Reference in New Issue
Block a user