I am using a bxSlider plugin to create a JS web application. On one slide there is a form which needs to be validated before I can get to a next slide. For validation I use jQuery Validate plugin which returns true / false when the form is valid.
How to make bxSlider not to go to next slide when form is not valid? I would prefer to use default bxSlider next/prev controls.
Function that initialize bxSlider:
bxSliderInit: function() {
var $slider = $(dom.slider);
$(dom.body).on('click', dom.pageLink, function(e) {
e.preventDefault();
_this = $(this);
slideFinished = true;
//newSlide = _this.data('slide-index');
app.slidePaging();
});
slider = $slider.bxSlider({
mode: 'horizontal',
easing: 'ease-out',
infiniteLoop: false,
touchEnabled: false,
preventDefaultSwipeY: true,
preventDefaultSwipeX: true,
responsive: false,
slideWidth: 1024,
pager: false,
prevText: '<i class="icon icon-arrow-left"></i>',
nextText: '<i class="icon icon-arrow-right"></i>',
onSlideBefore: function($slideElement, oldIndex, newIndex) {
app.slideValidation($slideElement, oldIndex, newIndex);
}
});
},
BxSlider callback onSlideBefore to validate the form
slideValidation: function($slideElement, oldIndex, newIndex) {
var $thisSlidevalidationForm = $(dom.slider).children().eq(oldIndex).find(dom.formValidationClass),
validationFromExist = $thisSlidevalidationForm.length > 0 ? true : false;
if (oldIndex < newIndex) {
if (validationFromExist) {
if (!$thisSlidevalidationForm.valid()) {
//slider.dontDoTransition
}
}
}
},
Everything seems to work fine, I just can't force the bxSlider to stay on the current slide when the form is not valid...
Thank u for ur help!