Hi,
When the user completes the form without errors, the default submit is prevented, as expected. However if the user makes an error, fixes it, then proceeds through to submitting the form, the default submission is not prevented and the form submits and the page reloads.
What am I doing wrong here?
Thanks in advance!
When the user completes the form without errors, the default submit is prevented, as expected. However if the user makes an error, fixes it, then proceeds through to submitting the form, the default submission is not prevented and the form submits and the page reloads.
What am I doing wrong here?
Thanks in advance!
$(function(){
$("#frmRegistration").validator().submit(function(e){
var form = $(this);
// client-side validation OK.
if (!e.isDefaultPrevented()) {
alert('validation ok')
// prevent default form submission logic
e.preventDefault();
}
});
var root = $("#wizard").scrollable();
var api = root.scrollable();
// validation logic is done inside the onBeforeSeek callback
api.onBeforeSeek(function(event, i) {
if (api.getIndex() < i) {
var page = root.find(".page").eq(api.getIndex())
inputs = page.find(":input").validator()
// if there are invalid fields, then
if (!inputs.data("validator").checkValidity()) {
alert("invalid");
return false;
// everything is good
}
alert('all is good');
}
// update status bar
$("#status li").removeClass("active").eq(i).addClass("active");
});
});
<form class="BM" id="frmRegistration" autocomplete="off">
<div id="wizard">
<ul id="status">
<li class="active">Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
<li>page 4</li>
</ul>
<div class="items">
<div class="page" id="page1">
<input type="text" required="required" name="first" id="first"/>
<button type="button" class="prev" style="float:left">Back</button>
<button type="button" class="next right">Next</button>
</div>
<div class="page" id="page2">
<button type="button" class="prev" style="float:left">Back</button>
<button type="button" class="next right">Next</button>
</div>
<div class="page" id="page3">
<button type="button" class="prev" style="float:left">Back</button>
<button type="button" class="next right">Next</button>
</div>
<div class="page" id="page4">
<button type="button" class="prev">Back</button>
<input type="submit" value="submit" id="btnSubmit" name="btnSbmit" />
</div>
</div><!---items--->
</div><!---wizard--->
</form>
