2016-08-02 44 views
0

我有2 inputTexts,一个设置上限和另一个设置下限(数值)。大于inputText javascript验证器

的视图:(代码和代码下当我按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

我应该怎么做才能使此验证器工作?

回答

0

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

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

..这并不意味着你的代码将工作..它只是一个提示,以解决您的语法问题