Dojo 动态创建的validationbox中的Dijit验证器问题,请提供帮助

Dojo 动态创建的validationbox中的Dijit验证器问题,请提供帮助,dojo,validation,Dojo,Validation,我现在尝试使用dijit按钮和验证框来创建一个动态创建的表行 按钮id和文本框id是由索引号生成的,所以我的Validation box validator如何知道哪行validationbox正在调用validator 作为validator:function(){testcall(this.id)},我应该进行validator:testcall吗 function createNewRow() { var tablebodyname = "RPDetailbody" ;

我现在尝试使用dijit按钮和验证框来创建一个动态创建的表行

按钮id和文本框id是由索引号生成的,所以我的Validation box validator如何知道哪行validationbox正在调用validator

作为validator:function(){testcall(this.id)},我应该进行validator:testcall吗

function createNewRow() {

    var tablebodyname = "RPDetailbody" ;

    var mytablebody     = document.getElementById(tablebodyname);
    var thetabletr      = document.createElement('tr');
    var thetabletd1     = document.createElement('td');
    var thetabletd2     = document.createElement('td');
    var thetabletd3     = document.createElement('td');

    var thisButton = new dijit.form.Button({
        label : thelineindex ,
        id : "I_del_butt"+thelineindex,
        name : "I_del_butt"+thelineindex,
        onClick : function() {
                    document.getElementById(tablebodyname).removeChild(thetabletr);
                    }
        }).placeAt( thetabletd1 ) ;

    var thisNumberTextBox = new dijit.form.NumberTextBox({
        id : "I_seq_no"+thelineindex ,
        name : "I_seq_no"+thelineindex ,
        value : thelineindex+1 ,
        required : "true",
        maxLength : 2,
        size : 2 ,
        style : "width: 2em;",
        missingMessage : "Every line must have sequence number"}).placeAt(thetabletd2) ;

    var thisValidationTextBox1 = new dijit.form.ValidationTextBox({
        id : "I_pig_code"+thelineindex ,
        name : "I_pig_code"+thelineindex ,
        type : "text" ,
        required : "true",
        maxLength : 3,
        size : 3,
        style : "width: 5em;",
        validator : testcall ,
        missingMessage : "Must have pigment code" }).placeAt(thetabletd3) ;

    thetabletr.appendChild(thetabletd1);
    thetabletr.appendChild(thetabletd2);
    thetabletr.appendChild(thetabletd3);

    mytablebody.appendChild(thetabletr);

    thelineindex ++ ;
}

你可以做:

var thisValidationTextBox1 = new dijit.form.ValidationTextBox({
    id: "I_pig_code" + thelineindex,
    name: "I_pig_code" + thelineindex,
    type: "text",
    required: "true",
    maxLength: 3,
    size: 3,
    style: "width: 5em;",
    missingMessage: "Must have pigment code"
}).placeAt(thetabletd3);

thisValidationTextBox1.validator = function() { 
    return testcall(thisValidationTextBox1.id); 
};
例如,您需要将
id
传递给
testcall()
函数,但还需要显式重写小部件的
验证程序
属性


请参阅Dojo参考指南中的。

我认为您必须使用包装函数显式传递id,是的。但是你说
form.isValid()
总是返回false-你确定这是因为
testcall
,还是因为表单中的另一个小部件无效?我知道了,isValid总是返回false,因为我缺少pigcode;在bNoNameFound部分=真;此外,我发现还有另一种方法:我可以通过约束传递ID:=====================================================================================================================函数测试调用(值,约束){var thebtnID=constraints.ID;========================================================================var thisvalidatetextbox1=新的dijit.form.ValidationTextBox({ID:“I_猪代码”+线索引,名称:“I_猪代码”+线性索引,类型:“text”,必需:“true”,最大长度:3,大小:3,样式:“width:5em;”,约束:{id:“I_pig_code”+线性索引},验证程序:testcall,missingMessage:“必须有颜料代码”});
    function testcall ( thebtnID ) {

        var strlen = thebtnID.length ;
        var resultAreaID = "I_pigment_name"+ thebtnID.substring(10, strlen) ;

        var pigcode = dijit.byId(thebtnID );
        var bNoNameFound =  ( "Error" == pigcode.get( "state" ) ) ? false:true;
        var query = "thePig=" + encodeURI(pigcode.value );

        if( "" == pigcode.value ) {

        // for some required=true is not kicking in, so we are forcing it.
            bNoNameFound = false;
            pigcode._setStateClass();

        } else {

            if( false ==  pigcode._focused ) {
                console.log( "Checking Pigment..." );
                dojo.xhrPost({
                    url: 'ValidatePigmentInput.php',
                    handleAs: 'text',
                    postData: query ,
                    load: function( responseText ) {
                        if ( responseText == "no record!" ) {
                            // setting the state to error since the pigment is already taken
                            bNoNameFound = false;
                            pigcode.set( "state", "Error" );
                            //pigcode.displayMessage( "The Pigment dosen't exist..." );
                            document.getElementById(resultAreaID).innerHTML = "The Pigment dosen't exist...";
                            // used to change the style of the control to represent a error
                            pigcode._setStateClass();
                        } else {

                            if ( responseText == "pigment BANNED!" ) {
                                bNoNameFound = false;
                                pigcode.set( "state", "Error" );
                                document.getElementById(resultAreaID).innerHTML = "Pigment BANNED! Please don't use it!";
                                pigcode._setStateClass();
                            } else {
                                bNoNameFound = true;
                                pigcode.set( "state", "" );
                                document.getElementById(resultAreaID).innerHTML = responseText;
                                pigcode._setStateClass();

                            }
                        }
                    },
                    error: function(responseText) {
                        document.getElementById(resultAreaID).innerHTML = "Error";
                    }
                });
            }
        }

        return bNoNameFound;

    }
var thisValidationTextBox1 = new dijit.form.ValidationTextBox({
    id: "I_pig_code" + thelineindex,
    name: "I_pig_code" + thelineindex,
    type: "text",
    required: "true",
    maxLength: 3,
    size: 3,
    style: "width: 5em;",
    missingMessage: "Must have pigment code"
}).placeAt(thetabletd3);

thisValidationTextBox1.validator = function() { 
    return testcall(thisValidationTextBox1.id); 
};