Zend_Dojo 和 ValidationTextBox - 无效消息并不总是出现

发布于 2024-09-27 03:44:32 字数 759 浏览 0 评论 0原文

我通过 Zend Framework 按以下方式使用 Dojo ValidationTextBox:

$form->addElement('ValidationTextBox', 'procedureName', array(
    'label' => _('Procedure Name'),
    'value' => $alarm->procedureName,
    'attribs' => array(
        'required' => true,
        'invalidMessage' => 'Required!'
    )
));

同样,我的表单验证是这样设置的:

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

如果“procedureName”文本框为空,表单验证将阻止表单提交,但 Dojo 不会标记表单元素无效,也不显示“必填!”信息。事实上,只有当我之前单击它时,它才会标记表单元素(但仍然不会显示无效消息)。

如何从此页面重建行为,您可以在其中单击提交按钮之前没有单击任何必填字段,Dojo 将标记所有必填字段?

谢谢。

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

$form->addElement('ValidationTextBox', 'procedureName', array(
    'label' => _('Procedure Name'),
    'value' => $alarm->procedureName,
    'attribs' => 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜宝宝 2024-10-04 03:44:33

Dojo 允许以声明方式和编程方式使用其许多功能。
声明性用法使用带有非标准属性的标准 HTML 元素,这些非标准属性在页面加载时进行解析。可能会导致问题,因此 Zend Framework 默认使用编程方式;各种视图助手将生成 javascript 并将其推送到 dojo() 视图助手,以便在渲染时包含在内。
要指定声明性用法,只需调用静态 setUseDeclarative() 方法:

Zend_Dojo_View_Helper_Dojo::setUseDeclarative();

在表单初始化时。
这将允许任何非标准选项(例如“required”=“true”)包含在您的输入标记中。
dojox.validate 函数将起作用。

使用作为我的验证设置。

        <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>

我在表单标签内

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.

装纯掩盖桑 2024-10-04 03:44:33

错误是我应该使用 formWidget.validate(),而不是 formWidget.isValid()。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文