2016-01-04 79 views
0

我試圖用「語義表單驗證」插件來驗證輸入的長度,這樣的:語義UI表單驗證問題

$('.ui.form').form({ 
    fields: { 
     firstname: { 
      identifier: 'firstname', 
      rules: [{ 
       type: 'empty', 
       prompt: 'Please enter your name' 
      }] 
     }, 
     lastname: { 
      identifier: 'lastname', 
      rules: [{ 
       type: 'empty', 
       prompt: 'Please enter your name' 
      }] 
     }, 
     username: { 
      identifier: 'username', 
      rules: [{ 
       type: 'minLength[3]', 
       prompt: 'Please enter a username' 
      }] 
     }, 
     password: { 
      identifier: 'password', 
      rules: [{ 
       type: 'minLength[6]', 
       prompt: 'Please enter a password' 
      }] 
     }, 
     terms: { 
      identifier: 'terms', 
      rules: [{ 
       type: 'checked', 
       prompt: 'You must agree to the terms and conditions' 
      }] 
     } 
    } 
}); 

每一行工作得很好,但它不會驗證minLength規則和不斷收到錯誤。它說

形式:沒有規則匹配您指定的minLength

+0

你在哪個版本上?這是[小提琴](http://jsfiddle.net/andreyvk/kdLkfhfb/),效果很好。 – AVK

回答

1

我今天已經有同樣的問題之一。我嘗試了大量的變化。然後我去找了semantic.js源代碼中任何對minLength的引用(並且沒有任何內容!)。那時,我發現函數調用的長度跌跌撞撞

length .. // is at least string length 
    length: function(value, requiredLength) { 
     return (value !== undefined) 
     ? (value.length >= requiredLength) 
     : false 
     ; 
    }, 

//所以想我會給一個嘗試,它的工作,你會想到..

password: { 
      identifier: 'password', 
      rules: [{ 
       type: 'length[6]', 
       prompt: 'Please enter a password' 
      }] 
     }, 

//我使用的版本語義UI - 2.0 0.0。


我還在掙扎了一下語義UI的這個特點,我不能得到簡化語法的工作,也無法找到辦法把每場多個標準..有什麼建議?