The input was not found in the haystack

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

The input was not found in the haystack

Alexander Ermakov
This post has NOT been accepted by the mailing list yet.
Hi everyone! In Zend FrameWork 1 was method - setRegisterInArrayValidator(),
is there similar method in Zend Framework 2.0.0 or other right way to stop get message "The input was not found in the haystack" when i get select element from ajax?
Maybe InArray validator I must not disable at all?
Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: The input was not found in the haystack

samsonasik
just change the message with yours. i just posted a code in form this for example :

https://gist.github.com/3753984

hopefully helpfull ;)
Reply | Threaded
Open this post in threaded view
|

Re: The input was not found in the haystack

Alexander Ermakov
This post has NOT been accepted by the mailing list yet.
Thank you, but i don`t want change message! I search solution for disable InArray validator, which invoke automaticaly and check option of select element when i dinamically change option via ajax and send form.
luk
Reply | Threaded
Open this post in threaded view
|

Re: The input was not found in the haystack

luk
Alexander Ermakov wrote
Thank you, but i don`t want change message! I search solution for disable InArray validator, which invoke automaticaly and check option of select element when i dinamically change option via ajax and send form.
When you fire your ajax request try to create a new Zend\Form\Element\Select and set your values on the PHP side and return whole new element as a content and replace the old one in your callback. For temp measure this will work until you will find a better solution.
Cheers, -- Luke Mierzwa
Reply | Threaded
Open this post in threaded view
|

Re: The input was not found in the haystack

Alexander Ermakov
Thank you! If I understand you right, - when i creat new Select element and then will output one in view like that:

<?php
$this->layout('layout/suggest'); // clear layout
?>

<dt><?php echo $this->formLabel($this->select); ?></dt>
<dd><?php echo $this->formSelect($this->select); ?></dd>

But i anyway get message "The input was not found in the haystack".

Therefore i write own solution:
\library\Zend\Form\Element\Select.php
add this line
protected $inarrayvalidator = true;

then add new method:

protected function setInarray($inarray)
{
                return $this->inarrayvalidator = $inarray;
}

then change getValidator method to this:
    protected function getValidator($inarray)
    {
       
        if (null === $this->validator && ($this->inarrayvalidator === null || $this->inarrayvalidator === true)) {
            $validator = new InArrayValidator(array(
                'haystack' => $this->getValueOptionsValues(),
                'strict'   => false
            ));

            $multiple = (isset($this->attributes['multiple']))
                      ? $this->attributes['multiple'] : null;

            if (true === $multiple || 'multiple' === $multiple) {
                $validator = new ExplodeValidator(array(
                    'validator'      => $validator,
                    'valueDelimiter' => null, // skip explode if only one value
                ));
            }

            $this->validator = $validator;
        } else {
                        $this->validator = new \Zend\Validator\StringLength(array('min' => 1));
                }
        return $this->validator;
    }
and replace getInputSpecification to this:

    public function getInputSpecification()
    {
        $spec = array(
            'name' => $this->getName(),
            'required' => true,
            'inarrayvalidator' => $this->setInarray($this->getAttribute('inarrayvalidator')),
            'validators' => array(
                $this->getValidator($validator)
            )
        );

        return $spec;
    }

now when I want not use default validator "InArray" i use this:


$this->add(array(
        'name' => 'city',
        'type' => 'Zend\Form\Element\Select',
        'options' => array(
                'label' => 'Please select city',
               
        ),
        'attributes' => array(
                'id' => 'cityselect',
                'options' => $arrayoption,
                'autocomplete' => 'off',
        'inarrayvalidator' => false,
        ),
));

Maybe it's not quite right, but it works!