Skip to content

Bug fix: Update collection.rst #11944

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

Merged
merged 1 commit into from
Sep 26, 2019

Conversation

MarvinBlstrli
Copy link
Contributor

form.children returns the children of the parent form, but at this point we need the length of children of the childform.

Example:
If form.children|length returns 3 and you add some childs the counter count up the data-widget-counter attribute. But after submit (with validation errors) the attribute has "3" again.

Steps to reproduce:

  1. Add form with child form as collection type like the documentation mentioned
  2. Add validation to those fields
  3. Check value of data-widget-counter
  4. Click the "add" button and and some child fields (check value of data-widget-counter again)
  5. Leave empty and submit the form
  6. Now you see those fields with validation errors - check value of data-widget-counter - it has the same value from beginning (without fields added) and not the length of fields from child form

@javiereguiluz
Copy link
Member

Although it looks OK to me, let's ask to our form experts @xabbuh and @yceruto to please review this change before merging. Thanks!

@@ -182,7 +182,7 @@ And update the template as follows:
<ul id="email-fields-list"
data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}"
data-widget-tags="{{ '<li></li>'|e }}"
data-widget-counter="{{ form.children|length }}">
data-widget-counter="{{ form.emails|length }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is clear to me that the length of $form->children is not the same as the length of $form->children['emails'], so the fix is correct.

@javiereguiluz
Copy link
Member

javiereguiluz commented Sep 26, 2019

Thank you @MarvinBlstrli and thanks Yonel for the review!

javiereguiluz added a commit that referenced this pull request Sep 26, 2019
This PR was merged into the master branch.

Discussion
----------

Bug fix: Update collection.rst

form.children returns the children of the parent form, but at this point we need the length of children of the childform.

Example:
If form.children|length returns 3 and you add some childs the counter count up the data-widget-counter attribute. But after submit (with validation errors) the attribute has "3" again.

Steps to reproduce:
1. Add form with child form as collection type like the documentation mentioned
2. Add validation to those fields
3. Check value of data-widget-counter
5. Click the "add" button and and some child fields (check value of data-widget-counter again)
5. Leave empty and submit the form
6. Now you see those fields with validation errors - check value of data-widget-counter - it has the same value from beginning (without fields added) and not the length of fields from child form

Commits
-------

2814081 fix data-widget-counter
@javiereguiluz javiereguiluz merged commit 2814081 into symfony:master Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants