大于inputText javascript验证器

时间:2016-08-02 10:36:16

标签: javascript jquery validation jsf

我有2个inputTexts,一个设置上限,另一个设置下限(数字)。

视图:(代码和代码下捕获按F12时看到的元素)

<h:form id="form">

enter image description here

<h:inputText id="lowerLmt" styleClass="input-sm form-control required number    
 minlim" value="#{managedBean.min}"/>

enter image description here

<h:inputText id="upperLmt" styleClass="input-sm form-control maxlim"
 value="#{managedBean.max}"/>

enter image description here

</form>

根据这个example,我已经定义了验证器:

$.validator.addMethod("upper_limit_greater_than_lower_limit", function(){
return $('#upperLmt').val() >= $('#lowerLmt').val()
}, "The upper limit mut be grater than or equal to lower limit");

我试图验证表格:

$('#form').validate({
   rules: {
       upperLmt: {
           required: true,
           upper_limit_greater_than_lower_limit: true
       },
       lowerLmt: {
           requred: true,
           upper_limit_greater_than_lower_limit: true
       },
   }, 
});

我看到imputTexts的id是形式:id 因为我使用的是jsf组件。 如果我尝试验证表单witform:id我有错误    enter image description here

如何使此验证工具正常工作?

1 个答案:

答案 0 :(得分:0)

因为这不是有效的对象。 它应该是

rules: {
  form: { upperLmt: { .. },
          lowerLmt: { .. }
  }
}

..这并不意味着您的代码可以运行..它只是提示修复语法问题

相关问题