-
Notifications
You must be signed in to change notification settings - Fork 10
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
This form should not contain extra fields. #23
Comments
Yeah, if you don't use JS to drop the value field before form submit - then form events is the correct way to work around it. Thanks for sharing your solution with others! If you have ideas on how to improve the package - please, feel free to open a PR |
@bocharsky-bw experimenting with this some more and I think I found something that may be useful. In my form I have added an additional "update" button that sets the following options:
If the 'update' button is clicked the form is submitted and all front end and back end validation is disabled. Combine this with an updated on change listener which passes the update button through as the requester element: and you have no errors on change: Screen.Recording.2024-04-24.at.11.00.29.movSubmitting the form with the submit button still triggers HTML5 and backend validation. |
Hey @leevigraham , Oh wow, this is an interesting workaround! Thanks for such a detailed description with the nice demo! Hm, having 2 buttons is a bummer, but seems that do the trick, and probably the additional button might be hidden with CSS. Though I wonder if the behavior may be different in different browsers :/ So this workaround solves your issue? Do you think we can improve our docs by mentioning this? I'm still not sure we're not missing something simple here... Btw, I found another possible solution - Symfony Forms have public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'allow_extra_fields' => true,
]);
} Should also do the trick probably because will allow the form to accept additional fields not defined in the form type. However, it might pose security risks if not handled properly. |
@bocharsky-bw |
I think allowing extra fields is risky. Adding |
When submitting a form with a dependent field if the dependent field is not shown then a "This form should not contain extra fields." error is shown.
Video:
Screen.Recording.2024-04-19.at.20.50.53.mov
I'm not using any javascript to remove the
value
field before submission so the data is being submitted triggering the error.I've also implemented this with
PRE_SUBMIT
on the parent form which checks the view data, adds / removes thevalue
field and unsets the data which works without error.The text was updated successfully, but these errors were encountered: