1

我尝试将详细介绍如何为 dijit/form/TextArea 混合验证的帖子:Dojo validation of a textarea扩展到 dijit/Editor。

特别是让编辑在提交表格时表明它是必需的。

意识到编辑器的内容没有作为表单的一部分提交,我设置了编辑器内容的值,以便在编辑器的 onChange 事件时复制到隐藏的文本区域:提交 dijit 编辑器内容

但是,厄运,当我使用下面的代码时,编辑器会在表单提交时显示验证消息,无论其中是否有文本。

我还注意到萤火虫,如果我使用开箱即用的 Dijit/Editor,则在 onChange 事件上设置 textarea 的值 - 但在使用下面的混合小部件时未设置隐藏的 textarea 值。

    define("my_dijit/ValidationEditor",
        [ "dojo", "dijit", "dijit/_Widget",  "dijit/form/_FormWidget", "dijit/form /ValidationTextBox", "dijit/Editor"  ], function(dojo, dijit, _Widget, _FormWidget, ValidationTextBox, Editor) {
    return dojo.declare("my_dijit.ValidationEditor", [ dijit._Widget, _FormWidget, dijit.form.ValidationTextBox, dijit.Editor ], {

        invalidMessage: "This field is required",
        missingMessage: "A value is required",
        //regExp: "(.|\\s)*",

        // regExp: "(.|[\r\n])*",
        regExp: "(.|[\r\n|\r|\n])*",

        // postCreate() is called after buildRendering().  This is useful to override when 
        // you need to access and/or manipulate DOM nodes included with your widget.
        // DOM nodes and widgets with the dojoAttachPoint attribute specified can now be directly
        // accessed as fields on "this". 
        // Common operations for postCreate
        // 1) Access and manipulate DOM nodes created in buildRendering()
        // 2) Add new DOM nodes or widgets 

        postCreate : function() {
            this.inherited(arguments);

        },

        validate: function() {
            if (arguments.length==0) {
                return this.validate(false);
            }
                return this.inherited(arguments);
            },

            onFocus: function() {
                if (!this.isValid()) {
                    this.displayMessage(this.getErrorMessage());
                }
            },

            onBlur: function() {
                if (!this.isValid()) {
                  this.displayMessage(this.getErrorMessage());
                }
            }

    });
});

非常感谢您的考虑

4

0 回答 0