Oyeme
Oyeme

Reputation: 11225

How to disable html5 validation?(Leave post validation)(zend framework2)

I'm using select2 plugin so if I have the error on client side(html5) it shows me in a wrong position,because of the select2 plugin.(the position of the element)

I would like to disable html5 validation only for one specific element but leave the post validation.

$inputFilter = new InputFilter();   
 $this->add(array(
                'name' => 'supplierName',
                'type' => 'Text',
                'attributes' => array('id'=>'supplierName','required' => true)
            ));
$this->setInputFilter($inputFilter);

Upvotes: 1

Views: 214

Answers (1)

Andrew
Andrew

Reputation: 12809

Disable the validation on your form definition:

// example inside your form setup..

$this->add(array(
    'name' => 'fieldname',
    'attributes' => array(
        'type'  => 'text',
        'class' => 'something',
        'required'  => FALSE,
    ),
    'options' => array
          'label' => 'Some Field',
    ),
));

But leave it enabled in your input filter definition

// example in your input filter setup ..

$inputFilter->add($factory->createInput(array(
    'name'     => 'fieldname',
    'required' => TRUE,
    'filters'  => array(
        array('name' => 'Int'),
    ),
)));

It's the form definition which will decide if the input field gets the required attribute applied.

The actual input filter decides if it's required when you are validating the data (post or what ever)

I believe this would allow the field to be left blank without using any client side required check, but would then check to make sure the field is required when the input filter validation checks are performed.

Upvotes: 1

Related Questions