2016-08-02 43 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: { .. } 
    } 
} 

..這並不意味着你的代碼將工作..它只是一個提示,以解決您的語法問題