11.
Disable HTML5 Validation
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
8 Comments
I use for this tutorial symfony 3.1.4 and the FunFact field which is set nullable=true in the entity annotation does not render as required in HTML5.
Hey Jacek Dziurdzikowski
Are you using field-type-guessing, right? That's why Symfony detects that that field is able to be null, and hence, does not adds the required attribute.
Cheers!
Yes, I guess so, but I just added the comment to point out that it might be not necessary to disable html5 validation in advance, because its not the truth that Symfony renders all fields marked as required. However, I didn't check how Symfony treats custom data objects which about Ryan mentioned at the end of the course, but as I expect - there are no applicable ORM nullable annotations for them, but after all they can have standard validation applied - I'm curious if standard validation options may be reflected in html5 required fields or this can work only for submitted form.
Cheers!
Symfony has many out of the box validations depending on the field type that you choose, like for example, you can define a field as an Email field, then, if that field is required, symfony will validate that the input of that field has the form of an "email"
You can see all the available field types here: https://symfony.com/doc/cur...
> I'm curious if standard validation options may be reflected in html5 required fields
Yes, but only if that field is actually required.
I guess there is also another method to disable HTML5 validation.
With Symfony 2.3 I used to use the following statement:
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
In other words I put the novalidate parameter in the form markup instead of submit button.
Hey Fabrizio S. ,
You're right, your case is valid too. Actually, it's not something related to Symfony 2.3 but to HTML in general - it's just an HTML5 attribute. So you can disable HTML5 validation for button... or disable it for entire form - useful when you have more than one submit button in your form.
Cheers!
Yes indeed! It's just something that I used to do but of course has no connection with SF version :)
Good tip btw, thanks for sharing it ;) Actually, I had used it a lot before I discovered "formnovalidate" attribute for submit buttons :)
Cheers!
"Houston: no signs of life"
Start the conversation!