LargeTuna
LargeTuna

Reputation: 2824

Html5Validation

I am new to Html5 so go easy on me with this question...

I am trying to use HTML5 built in form validation. I am using Bootstrap as my framework. Each time I go to submit a form, when it validates it is putting the bubble way below the form fields that needs to be fix. It would seem to the end user as though it is the field below the one that has the error (Product Name is the one with the error). I have included a screen shot of what I am geting. Here is my markup: Thanks for your help!!!

<div class="control-group">
<label class="control-label required" for="product_name">Name</label>
<div class="controls">
    <input type="text" id="product_name" name="product[name]" required="required" placeholder="Product Name" class="span12" value="" />
</div>

enter image description here

Upvotes: 0

Views: 73

Answers (1)

Thomas Potaire
Thomas Potaire

Reputation: 6256

In your FormBuilder, turn off the option require and use Form Validation.

Example in ProductType.php

$builder->add('name', 'text', array(
    'label'    => 'Name',
    'required' => false   // this will remove the HTML5 error which in my opinion is meh
)); 

In your validation.yml

Your\AwesomeBundle\Entity\Product:
    properties:
        name:
            - NotBlank: ~  # when you call bindRequest on the form object it will validate the form data against that constraint

Make sure you check the Form Validation documentation because as of Symfony2.2 some constraints has changed.

Upvotes: 1

Related Questions