0

必要な入力があるフォームがありますが、jQueryは、フィールドが有効でない場合でも有効であると言っています。HTMLからすると、価値があるように見えるので、奇妙です。

これは、テキストボックスが完全に空のChromeコンソールでの3つのコマンドの出力です。

// 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を使用して動的に作成されています。

何が問題なのですか?

ありがとう。

4

1 に答える 1

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

入力を動的に追加するときに、もう一度呼び出す必要があることを知りませんでした。私はより多くのドキュメントとより少ない例を読まなければならないと思います:P

于 2011-08-05T17:07:44.903 に答える