I'm using Bootstrap 3 to create modal form. Before user click button to open the modal, there is a field validation.
If it is valid then modal is shown, otherwise prevent the modal from being shown.
The problem is on the second chance, user click the button and the modal won't display. How to solve this problem?
Code to show modal and prevent modal from being shown: jsfiddle
$("#btnLookupClient").click(function (e) { if ($("select[name='OfficeID'] option:selected").index() <= 0) { alert("Please select office"); $("#OfficeID").focus(); $("#clientModal").on("show.bs.modal", function (e) { return e.preventDefault() // stops modal from being shown }); } else { var url = '@Url.Content("~/Client/Search?officeID=")' + $("#OfficeID").val(); $.get(url) .done(function (data) { $("#lookup-client-container").html(data); $("#clientModal").modal(show = true, backdrop = true); }); } });
http://jsfiddle.net/rsxb8tku/