1

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);
3
  • 1
    Required should be 'required' => false Commented Jul 18, 2013 at 9:31
  • It works for both validations rules Commented Jul 18, 2013 at 9:39
  • Remember that the attributes array matches the HTML Attributes you are adding to an Element ;) Commented Jul 18, 2013 at 11:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.