简体   繁体   English

表格:如何为新添加的输入添加验证规则?

[英]Form: how to add a validation rule for a newly added input?

I have a Webix for which provides a possibility to add an additional text field that should be validated as well as predefined fields. 我有一个Webix,可以为它添加一个应该验证的附加文本字段以及预定义字段。

Something like next: http://webix.com/snippet/73c90f29 如下所示: http : //webix.com/snippet/73c90f29

function addFormInput(){
  $$("form1").addView({ 
    view:"text", 
    label:'Should be a number', 
    name:"text2",
    value:"some",
    labelPosition:"top"
  }, 1);
};


webix.ui({
  view:"form",
  id:"form1",
  elements: [
    { 
      view:"text", 
      label:'Not empty',  
      name:"text1",
      labelPosition:"top"
    },    
    {cols:[
      {
        view:"button", type:"iconButton", 
        label:"Add new", icon:"plus", 
        click:function(){
          addFormInput(); 
          this.disable()
        }
      }      
    ]}
  ],
  rules:{
    text1:webix.rules.isNotEmpty
  }
}); 

But I'm stuck with the adding a validation rule for a new item. 但是我坚持为新商品添加验证规则。 How to do that? 怎么做? Is it possible at all? 有可能吗? Thanks in advance! 提前致谢!

The new item is added in the form hence you can apply the validation rules on it in your form's rules definition as: 新项目将添加到表单中,因此您可以在表单的规则定义中将验证规则应用于该项目,如下所示:

rules:{
      text1:webix.rules.isNotEmpty,
      //text2 : webix.rules.isNotEmpty      // webix defined validation rule
      text2 : function(value){              // custom validation rule
                if (!value) return false;
                return true;
      }
}

You can apply custom or webix validation rules on the newly item as shown above. 您可以在新项目上应用自定义或webix验证规则,如上所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM