简体   繁体   English

删除验证zend表单元素javascript / jquery

[英]remove validation zend form element javascript/jquery

I want to disable the validation on one of the zend form element based on the input on another element on the same form. 我想基于同一表单上另一个元素的输入来禁用对zend表单元素之一的验证。 I need to achieve this using javascript/jquery. 我需要使用javascript / jquery实现此目的。 Something very common but very surprisingly couldn't find it over the internet. 在互联网上找不到很常见但很令人惊讶的东西。

eg 例如

In the controller: 在控制器中:

$oFormMassEdit = new Account_Form_Returns_Return();
$this->view->form = $oFormMassEdit;

In Account_Form_Returns_Return's constructor: 在Account_Form_Returns_Return的构造函数中:

$oNoteElement = new Zend_Form_Element_Textarea('option', array(
                                                'required'  => true,
                                  ));
$this->addElemet($oNoteElement)

$oReasonElement = new Zend_Form_Element_Select('note', array(
            'multiOptions'  => array (
                'return'  => 'return',
                'defect'  => 'Kaput',
                'other'   => 'Anderer Grund'
            ),
            'required'      => true,
                    ));
$this->addElement($oReasonElement);

$this->addDisplayGroup(array('note', 'option'), 'main', array('legend' => 'Retouren'));

$this->addElement('button','send', array(
           'type'   => 'submit',
           'label'  => 'Methode speichern',
        ));

and finally in the view, 最后在视图中,

<?= $this->form; ?>

Javascript can't (not in a sensible way) switch Zend_Form configuration. Javascript无法(以不明智的方式)切换Zend_Form配置。 What you can do is changing the 'required' param for certain form fields on validation. 您可以做的是更改验证中某些表单字段的“必需”参数。 For example; 例如; If you want to allow fieldTwo to be empty if fieldOne has 'desiredValue' as value you can achieve this using the following function in your form: 如果您希望在fieldOne具有'desiredValue'作为值的情况下允许fieldTwo为空,则可以使用以下形式的表单实现此目的:

public function isValid($data) {
    if('desiredValue' == $data['fieldOne'])) {
        $this->getElement('fieldTwo')->setRequired(false);
    }

    return parent::isValid($data);
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM