テキストフィールドが必要です。キーボードのリターンキーを押すと、クラスエラーが発生します(私のcssでは、正しい動作)。
テキストを挿入してからリターンキーを押すと、フォームは送信されますが、テキストフィールドは再びクラスエラーで戻ります
私のJavaScriptでは、これを使用してフォームをクリアします
$("#formid")[0].reset();
その他のコード
<form method="post" id="form_commento-3" class="form_fancybox_commenti">
<span style="position: relative">
<input type="text" id="commento_form_3_commento" name="commento_form_3[commento]" required="required" maxlength="100" class="small" placeholder="comment..." />
</span>
<button type="submit" class="submit-button" id="submit_form_commenti">Comment</button>
</form>
詳細フォームは、 jQuery Validate within jQuery .each() で非常によく似ています
私のjs:
$('.form_fancybox_commenti').each(function(index, numero_form) {
$("#commento_form_"+index+"_commento").addClass("alphanumeric");
$(this).validate({
submitHandler: function(form) {
console.log("form "+form);
save(form);
}
});
});
function save(form) {
var parametri = {};
parametri = $("#" + form.id).serializeArray();
// i try with
//$("#" + form.id)[0].reset();
//$("#form_commento-"+id).trigger('reset')
//$("#form_commento-"+id).get(0).reset();
save via node.js
}
この振る舞いは
- テキストフィールドを適切に埋める
- リターンキーを押します
- フォーム送信と私のテキストフィールドは問題ありません
もしも
- テキスト フィールドが正しく入力されていません (エラー jquery 検証)
- テキストフィールドを修正してリターンキーを押します
- フォーム送信とテキストフィールドが再びクラスエラーで返される
ありがとう