Since 1.8.0, all my fields are set as required by default and validated by the browser. This prevents the user to submit the form with null valued fields, even though those are being nullable.
Although I'm happy with HTML5 validation and don't want to disable it, I reckon the fields shouldn't be set as required by default, should they?
I had a look through the code but didn't come up with any fix, not sure how you guys handle your configuration system.
Actually, that's not a bug, that's Symfony's form types default behavior to be required. As we build the form and its fields without basing it on an entity (no data_class option on the root form), the type guessers are not able to guess if the field is required or not.
The simplest solution for you, is to use the easyadmin type_options on non-required fields:
form:
fields:
# ...
- { property: 'my_property', type_options: { required: false } }
If we want to fix this, I think we can create our own type guesser, or use the data_class option on our easyadmin type.
Forget about my comment, we use the data_class option. Didn't remembered that. So that's not where it comes from.
You can however use the above config sample to solve your issue.
@artggd thanks for reporting this issue.
In the past we disabled the HTML5 validation, because we think that the default Symfony form behavior is annoying (your issue clearly shows that!).
Recently we enabled the HTML5 validation ... but we disabled it for checkboxes. I need to read some more opinions about this before doing any change.
For now, you can disable validation by form by setting this option:
easy_admin:
entities:
Customer:
class: AppBundle\Entity\Customer
form:
form_options: { validation_groups: false } # <-- ADD THIS
# ...
@javiereguiluz: I can't manage to get your solution working, I still get the HTML validation blocking the submission. Rolling back to 1.7.x for now, I'm not keen on updating all the fields in my admin.yml file.
I'll keep up to date with this issue and may have a closer look tonight.
@artggd : I made a PR related to this issue that might help you once the next release is published: #565
I think this issue could be closed :)
Brilliant! Looking forward for the next release then.
Thanks @ogizanagi !
This should be fixed by the new 1.9.0 version. Please, upgrade and test it. Thanks!
I had this issue (v1.14.0), required: false was not taken into account.
I had to use validation_groups: false on the field type_options.
The issue is I would not be able to add another constraint.
Most helpful comment
Actually, that's not a bug, that's Symfony's form types default behavior to be required. As we build the form and its fields
without basing it on an entity (nodata_classoption on the root form), the type guessers are not able to guess if the field is required or not.The simplest solution for you, is to use the easyadmin
type_optionson non-required fields:If we want to fix this, I think we can create our own type guesser, or use thedata_classoption on oureasyadmintype.Forget about my comment, we use the
data_classoption. Didn't remembered that. So that's not where it comes from.You can however use the above config sample to solve your issue.