0

我有一個表單,具有所需的輸入,但jQuery的說,該字段是有效的,當它不是。這很奇怪,因爲通過HTML看起來它有價值。jQuery unobstrusive驗證返回有效時,它不是

這三個命令的輸出在Chrome控制檯與文本框完全空:

// First I ensure that the selector is correct. But I can see that it has value, 
// when it is actually empty. 
$('#form_0 input[name=Name]')[0].outerHTML 

"<input data-val="true" data-val-length="The field Customer name must be a string with a minimum length of 3 and a maximum length of 20." data-val-length-max="20" data-val-length-min="3" data-val-required="The Customer name field is required." id="Name" name="Name" type="text" value="    Customer 0   " class="valid">" 

// jQuery confirms that the field is empty 
$('#form_0 input[name=Name]').val() 

"" 

// but jQuery say that the control is valid :? 
$('#form_0 input[name=Name]').valid() 

1 

的形式和輸入已經被用jQuery動態創建的。

可能是什麼問題?

謝謝。

+0

你能給一個網站的URL來測試嗎? –

+0

不幸的是,我會嘗試做一個概念驗證,我會把它放在這裏。 – vtortola

回答

0
$.validator.unobtrusive.parse('#form_0'); 

我不知道當我動態添加輸入時,我不得不再次調用它。我想我必須閱讀更多的文檔和更少的例子:P

相關問題