Disable notInArray Validator Zend Framework 2
Asked Answered
K

5

11

Is there a way to disable notInArray Validator in Zend Framework 2. All the info on the internet shows how to disable the notInArray Validator in Zend Framework 1, for example in this fashion

If you do not want the InArray validator at all, you can disable this behavior by either calling setRegisterInArrayValidator(false) on the element, or by passing false to the registerInArrayValidator configuration key on element creation.

One the posts in stackoverflow can be found here

Unfortunately this is not possible in Zend Framework 2. So in case if anybody has a tip how this can be disabled.

Kanya answered 1/11, 2012 at 9:58 Comment(4)
Erm, validators get only attached if you tell them to. Where exactly do you want the validator to not be attached to? Your question is simply not clear at all, please update so people can get a better understanding of your prblemEarhart
Hey Sam! I have a select with no validator at all but ZF2 keeps saying that The input was not found in the haystack. Why this happens?Cholinesterase
this Not in array is default validatorIa
And how can I change an default validator?Cholinesterase
S
10

Since version 2.2, Zend Framework provide the ability to disable inArray validator calling:

$element->setDisableInArrayValidator(false);

or passing option to an element:

'disable_inarray_validator' => false
Sublimity answered 13/5, 2013 at 13:29 Comment(1)
Okay, but a bit different. To disable you should to 'disable_inarray_validator' => true, since twice negation is approval.Empower
S
3

I had the same problem and what i did is populate the element before validate it, for example:

$clientForm->get('city')->setValueOptions($options);
$clientForm->setData($post);

if ($clientForm->isValid()) {
  //
} else {
  //
}

This don't disable notInArray valitador but you can trick it.

Skied answered 18/1, 2013 at 17:9 Comment(0)
I
0

I came with the same case : while i was populating my html select element via ajax after alot of searching found no way to do it , ending with creating my own select form element , I will provide you with my changes :

    /**
     * Provide default input rules for this element
     *
     * Attaches the captcha as a validator.
     *
     * @return array
     */
    public function getInputSpecification()
    {
        $spec = array(
            'name' => $this->getName(),
            'required' => true,
            //// make sure to delete the validators array in the next line  
            'validators' => array( 
                $this->getValidator()
            )
        );

        return $spec;
    }
Ia answered 7/11, 2012 at 13:4 Comment(0)
E
0

I found this at this link and thought I would post it as I found it a great solution .... http://samsonasik.wordpress.com/2012/10/01/zend-framework-2-extending-zendform-to-add-select-multicheckbox-emaildate-textarea-and-radio-element/

don’t try to deactive the default validator. re-values the select options values before setData.

$form->get('state_id')
     ->setOptions(
           array('value_options'=> $Newstatecollection)) ;

Saves the mess of deactivating the function if you need it elsewhere

Equiponderate answered 2/3, 2013 at 3:5 Comment(0)
I
0

If you don't need validation at all, add required => false in InputFilter

    $this->add(array(
        'name' => 'your-elements-name',
        'required' => false,
    ));

worked for me..

Indiscipline answered 2/12, 2013 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.