Reputation: 117
I have a form with three buttons. One for adding objects, one for deleting and one for editing objects.
I now want to disable html5-validation in the add-button using the new form buttons introduced in Symfony 2.3. Is this possible or do I have to create a new button type? How could I do that?
Upvotes: 2
Views: 4681
Reputation: 2989
To disable form validation, use formnovalidate
on submit button.
For example:
<div class="row">
<input type="email">
<input formnovalidate type="submit" value="Remove row">
</div>
<div class="row">
...
</div>
<input type="submit" value="Submit rows">
Note the formnovalidate
is on the remove button, so even if field next to it contains invalid e-mail, it still can be removed. The real submit button does not have the formnovalidate attribute, so all e-mail must be valid before actually submitting the form.
Upvotes: 7
Reputation: 48865
All you need to do is to add the html attribute novalidate or novalidate="novalidate" to the element. You can do this same way you would add any other attribute from either the form type of the twig template. For example:
{{ form_widget(form.add, { 'attr': {'novalidate': 'novalidate' }}) }}
Actually, reading your question again, I'm not entirely sure what sort of validation you are trying to do on a button. You have to put novalidate on all the elements that you don't want to validate.
You can also put novalidate on the form itself:
<form action="demo_form.asp" novalidate>
Upvotes: 4