开发者

In ExtJS, Can I pass argument via vtype?

I can't find the way to pass argument via vtype.

So I do some onfly vtype function.

var vtypeMaker = function(n){
    Ext.apply(Ext.form.VTypes, {
        myTest : function(v, o){
            console.debug(n); // <-- I can pass my custom value
            // do something
            // ...
            return myRegex.test(v);
        },
        myTestText : 'some message'
    });
}

And when I want to set vtype, I should call this function first.

vtypeMaker(10);
myTextfield.vtype = 'myTes开发者_StackOverflowt';

It works but too long code.

Anyone has better idea ?

Thanks.


Use the validator config to pass a custom validator function and use createDelegate to customize the parameters that will be sent to it:

var myValidator = function( value, custom ) {
    if ( /* value is valid */ ) {
        return true;
    }
    else {
        return 'Field value is not valid';
    }
};

new Ext.form.TextField({
    fieldLabel: 'A text field',
    validator: myValidator.createDelegate(null, [10], true);
});

new Ext.form.TextField({
    fieldLabel: 'Another text field',
    validator: myValidator.createDelegate(null, [14], true);
});

The custom parameters are set in the second parameter to createDelegate. Setting the third parameter to true will result in those custom parameters being appended to the parameters the function was called with (in this case, the field value).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜