可以将dojo验证器函数存储到变量中,以便以后调用它
It is possible to store a dojo validator function into a variable to invoke it later
要自定义dojo NumberTextBox的验证器,dojo ValidationTextBox。。。我需要将默认验证器存储在js上下文中的某个位置,以便以后能够调用它;自定义验证取决于默认验证程序的结果。
这样做是可能的,你能帮我做吗?
非常感谢
代码示例:
var djNumberTextBox1 = dijit.byId('#{id:djNumberTextBox1}');
djNumberTextBox1.validator = function() {
var valide = true;
//here I'd like to invoke the default (old) validator (something like next line)
//var valide = djNumberTextBox1.validate();//but this causes a too much recursion because validate() references the current function
//customisation depending on the default (old) validator result
var djButton1 = dijit.byId('#{id:djButton1}');
if(!valide){
djButton1.setDisabled(true);
}else{
djButton1.setDisabled(false);
}
return valide;};
您可以尝试以下代码吗:
var djNumberTextBox1 = dijit.byId('#{id:djNumberTextBox1}');
// store the validator in _oldValidator
djNumberTextBox1._oldValidator = djNumberTextBox1.validator;
djNumberTextBox1.validator = function() {
var valide = true;
// Run the old validator
valide = djNumberTextBox1._oldValidator();
//customisation depending on the default (old) validator result
var djButton1 = dijit.byId('#{id:djButton1}');
if(!valide){
djButton1.setDisabled(true);
}else{
djButton1.setDisabled(false);
}
return valide;};
编辑1:
已将参数传递给验证器函数。
var djNumberTextBox1 = dijit.byId('#{id:djNumberTextBox1}');
// store the validator in _oldValidator
djNumberTextBox1._oldValidator = djNumberTextBox1.validator;
djNumberTextBox1.validator = function(value, constraints) {
var valide = true;
// Run the old validator with arguments
valide = djNumberTextBox1._oldValidator(value, constraints);
//customisation depending on the default (old) validator result
var djButton1 = dijit.byId('#{id:djButton1}');
if(!valide){
djButton1.setDisabled(true);
}else{
djButton1.setDisabled(false);
}
return valide;};
编辑2:
我认为对于NumberTextBox调用validate()。
var djNumberTextBox1 = dijit.byId('#{id:djNumberTextBox1}');
// store the validate in _oldValidate
djNumberTextBox1._oldValidate = djNumberTextBox1.validate;
djNumberTextBox1.validate = function() {
var valide = true;
// Run the old validate
valide = djNumberTextBox1._oldValidate();
//customisation depending on the default (old) validate result
var djButton1 = dijit.byId('#{id:djButton1}');
if(!valide){
djButton1.setDisabled(true);
}else{
djButton1.setDisabled(false);
}
return valide;};
是的,您可以使用"单音对象"或当前对象的属性来添加任何用于"验证"的信息,并在需要时从NumberTextBox重新访问该值。
相关文章:
- 如何在侦听器中调用变量
- 调用变量中分配的 url
- 如何在文档准备函数中调用变量的click函数
- 调用变量为paramenter的函数
- Javascript:为什么我把“;()“;在console.log中调用变量时在变量后面
- Javascript从HTML表单中调用变量
- Kinetic.js / Javascript:在不使用 eval() 的情况下调用变量作为属性
- 如何在 jquery 中用变量调用变量
- 如何将选择复选框值动态传递给 ajax 调用变量动态发布到 php 变量
- JS:从函数外部调用变量
- 如何通过在javascript中引用来调用变量
- 调用变量以引用数组
- 如何在jQuery中通过字符串值调用变量
- 从一个函数调用变量到另一个函数
- 如何在 php 文件中从我的 javascript 调用变量
- 我可以在 Chrome 打包应用中从后台页面调用变量或函数吗?
- 调用变量 jQuery 函数
- jQuery ajax 调用变量
- 如何在点击函数之外调用变量
- json调用变量名