dijit / Editor的dojo验证

时间:2013-09-19 20:40:16

标签: javascript forms validation dojo editor

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

特别要让编辑在表格提交时表明其必要性。

知道编辑的内容没有作为表格的一部分提交我设置编辑内容的值,在编辑的onChange事件中被复制到隐藏的文本区域:Submit the dijit editor contents

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

我还注意到firebug,如果我使用开箱即用的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());
                }
            }

    });
});

非常感谢您的任何考虑

0 个答案:

没有答案