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

[Form] Fix "prototype_data" option creating duplicates instead of new lines #50056

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

Thorry84
Copy link
Contributor

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #49961
License MIT

Fix for issue 49961.

Changed the prototype options passed to the ResizeFormListener to prevent prototype_data from being passed to new fields.

@@ -36,6 +36,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$prototype = $builder->create($options['prototype_name'], $options['entry_type'], $prototypeOptions);
$builder->setAttribute('prototype', $prototype->getForm());

$resizeFormListenerPrototypeOptions = array_replace($options['entry_options'], $options['prototype_options']);
Copy link
Member

Choose a reason for hiding this comment

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

What about the options set on L29-30, do we want them in this array?
Sorry I'm not much into this domain so this might be a dumb question.

Copy link
Contributor Author

@Thorry84 Thorry84 Apr 19, 2023

Choose a reason for hiding this comment

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

Very good question, I was wondering about that as well.

Those provide some default values in case they aren't provided via the entry_options and prototype_options array. Since required defaults to true, a collection with required set to false would have the entries set to required. (See issue #15544)

However since the entry_options and later the prototype_options have been introduced, this behavior is kind of redundant.

Same for the label, this is because otherwise the label isn't rendered as a replaceable string when using prototype_name as a label. Since the prototype is normally used to add new fields to a form using JS, it's important to have them be replaceable (see issue #3738). For the new fields rendered server-side, the prototype_name isn't used, so the label for the prototype shouldn't be used.
I'm not sure of the use case for falling back to the prototype_name as a label, but it's being kept the same for BC reasons.

So I think we don't want those values in the array and only use entry_options and prototype_options for the ResizeFormListener.

@nicolas-grekas nicolas-grekas changed the title Fix issue 49961 see also 49835 [Form] Fix "prototype_data" option creating duplicates instead of new lines Apr 19, 2023
@nicolas-grekas
Copy link
Member

Thank you @Thorry84.

@nicolas-grekas nicolas-grekas merged commit 9463872 into symfony:6.2 Apr 19, 2023
3 of 7 checks passed
@fabpot fabpot mentioned this pull request Apr 28, 2023
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.

None yet

3 participants