my project function only needs to add, delete, modify and query the form, and find problems when dealing with adding and editing
whether I add or edit, I need to adjust a mode box, and it is the same mode box (because I don"t want to write more than one), so I can"t submit correctly after repeatedly clicking between editing and adding. For example, I want to edit and become add
.the following figure shows the modal box when you click to add
(, )
my code looks like this:
html
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
// ....
<form id="myModal-form">
<div class="modal-body">
<!-- tab -->
// ...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"></button>
<button type="submit" class="btn btn-primary"></button>
</div>
</form>
</div>
js for adding features
$(".page-content-header .site-add").click(function () {
$("-sharpmyModal-2").modal("show");
$("-sharpmyModal-form").validate({
rules: {...},
//
submitHandler: function () {...} // jquery-validate
})
})
js of the editing function
$("-sharptemp-layout").on("click", ".amend", function () {
$("-sharpmyModal-2").modal("show");
$("-sharpmyModal-form").validate({
rules: {...},
submitHandler: function () {...}
})
})
question: the click event is triggered when I click to edit. The modal box displays, then cancel without submission, and then click the interface that is actually edited by the API that is called by filling in the form data after adding.
under the premise of still calling the same mode box, is there any way to solve the current problem