4

我在我的表格中使用它:

$this->add(array(     
    'type' => 'Zend\Form\Element\Select',       
    'name' => 'county',
    'registerInArrayValidator' => false,
    'attributes' =>  array(
        'id' => 'county',                
        'options' => array(
            //'null'=>'[Select county]',
        ),
    ),
    'options' => array(
        'label' => 'county',
    ),
));

并用js设置值县字段。验证后,我得到错误: haystack 选项是强制性的

4

3 回答 3

10

将 disable_inarray_validator 添加到选项中:

$this->add(array(
    ...
    'options' => array(
        'disable_inarray_validator' => true,
        'label' => 'county',
    ),
));
于 2013-06-06T08:54:45.113 回答
2

In https://github.com/zendframework/zf2/blob/master/library/Zend/Form/Element/Select.php there is an option $disableInArrayValidator = false; and the corresponding method here

于 2013-05-11T08:26:00.317 回答
0

在 ZF1 中,这是有效的:

// using the element instance:
$element->setRegisterInArrayValidator(false);

// or a configuration key as part of the options array:
'registerInArrayValidator' => false

// or
element.options.registerInArrayValidator = false
于 2020-09-23T05:44:22.473 回答