开发者

Zend_Dojo and ValidationTextBox - invalid message does not always appear

I am using Dojo ValidationTextBox through Zend Framework in the following way:

$form->addElement('ValidationTextBox', 'procedureName', array(
    'label' => _('Procedure Name'),
    'value' => $alarm->procedureName,
    'attribs' =&开发者_如何学编程gt; array(
        'required' => true,
        'invalidMessage' => 'Required!'
    )
));

Likewise, my form validation is set up in this way:

if (formWidget.isValid()) {
    return true;
} else {
    alert('Invalid form.');
    return false;
}

Form validation will prevent the form from submitting if "procedureName" text box is blank, but Dojo will not mark the form element as invalid, nor display the "Required!" message. In fact, it will mark the form element only if I click it previously (but still, will not display the invalid message).

How can I reconstruct the behavior from this page, where you can click the submit button without clicking on any of required fields previously, and Dojo will mark all required fields?

Thanks.


Dojo allows both declarative and programmatic usage of many of its features. Declarative usage uses standard HTML elements with non-standard attributes that are parsed when the page is loaded. Can cause issues so Zend Framework uses programmatic usage by default; the various view helpers will generate javascript and push it to the dojo() view helper for inclusion when rendered. To specify declarative usage, simply call the static setUseDeclarative() method:

Zend_Dojo_View_Helper_Dojo::setUseDeclarative();

When in your form initialization. This will allow any non standard options like "required" = "true" to be included in your input tag. dojox.validate function will then work.

I use

        <script type="dojo/method" event="onSubmit">
        if (this.validate()) {
            //return confirm('Form is valid, press OK to submit');
        } else {
            //alert('Form contains invalid data.  Please correct first');
            return false;
        }
        return true;
    </script>

inside my form tags as my validation setup.


The error was that I should've used formWidget.validate(), instead of formWidget.isValid().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜