Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent name collision #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Arzamendiaariel
Copy link

@Arzamendiaariel Arzamendiaariel commented Mar 20, 2024

When using the stimulus-rails-nested-form library to dynamically add nested form fields, it has been observed that if the "add" action is triggered multiple times, the newly added input fields end up having the same name attribute value. This behavior results in only the last input's data being submitted, as the preceding input values are overwritten due to the shared name attribute among them. This issue fundamentally affects the form's ability to correctly handle multiple nested records, leading to data loss and inconsistent submissions.

I propose modifying the nested form field addition process to include a unique identifier within each name attribute of newly added input fields. This can be achieved by appending a timestamp or a sequentially incremented value to the name attribute, ensuring its uniqueness across the form. I have prepared a pull request that implements this solution by extending the current functionality of the stimulus-rails-nested-form library's controller to include this adjustment.

@Arzamendiaariel
Copy link
Author

I change the code as we need to generate mutiple instances of nested form one inside another and therefore create custom targets based on the values, so we can nest mutiple instances
data-controller="nested-form"
data-nested-form-wrapper-selector-value=".my-nested-form-wrapper"
data-nested-form-target-value="customTarget"
data-nested-form-template-value="customTemplate"
data-nested-form-record-placeholder-value="MY_CUSTOM_PLACEHOLDER"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant