我有一個窗體有多個輸入和下拉字段。提交前我需要確認。所以,我已經添加對話框,確認形式由Submit
或Cancel
提交,我已經阻止默認提交。如何使用jquery驗證動態表單域?
現在,當我使用自定義功能來驗證使用jquery
工作不投入。
即使當我做輸入字段這樣的:
<form class="form-horizontal" action="{{URL::to('quick/make/reservation')}}" method="post" role="form" id="confirm_request">
<input type="text" name="contact" id="contact">
<span id="error">
</span>
<a class="btn btn-default" data-toggle="modal" data-target="#confirm-verify" id="done">Done</a>
</form>
<div class="modal fade bd-example-modal-sm" id="confirm-verify" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="text-left bold-text">Are you sure you want to Complete Reservation ?</p>
</div>
<div class="modal-body">
<a type="button" class="btn btn-xs btn-danger btn-ok btn-sm" onclick="event.preventDefault();
document.getElementById('confirm_request').submit();" style="cursor: pointer;">Submit</a>
<a type="button" class="btn btn-xs btn-primary btn-sm" data-dismiss="modal">Cancel</a>
</div>
</div>
</div>
</div>
空數據已提交。我很新JQuery
。
$('#done').click(function(event){
var is_filled = true;
var value = $('#contact').val();
if(!value){
is_filled = false;
}
if(!is_filled){
event.preventDefault();
$('#error').append('<strong>The field is required </strong>')
}
});
任何人都有想法,我做錯了什麼?
你可以請顯示你試過的jQuery代碼 –
你可以添加你的代碼jsfiddle鏈接 – hasan
@PankajMakwana我已更新。 –