jumps to the next field
*/
FForm.prototype._nextField = function( backto ) {
if( this.isLastStep || !this._validade() || this.isAnimating ) {
return false;
}
this.isAnimating = true;
// check if on last step
this.isLastStep = this.current === this.fieldsCount - 1 && backto === undefined ? true : false;
// clear any previous error messages
this._clearError();
// current field
var currentFld = this.fields[ this.current ];
// save the navigation direction
this.navdir = backto !== undefined ? backto < this.current ? ‘prev’ : ‘next’ : ‘next’;
// update current field
this.current = backto !== undefined ? backto : this.current + 1;
if( backto === undefined ) {
// update progress bar (unless we navigate backwards)
this._progress();
// save farthest position so far
this.farthest = this.current;
}
// add class “fs-display-next” or “fs-display-prev” to the list of fields
classie.add( this.fieldsList, ‘fs-display-’ + this.navdir );
// remove class “fs-current” from current field and add it to the next one
// also add class “fs-show” to the next field and the class “fs-hide” to the current one
classie.remove( currentFld, ‘fs-current’ );
classie.add( currentFld, ‘fs-hide’ );
if( !this.isLastStep ) {
// update nav
this._updateNav();
// change the current field number/status
this._updateFieldNumber();
var nextField = this.fields[ this.current ];
classie.add( nextField, 'fs-current' );
classie.add( nextField, 'fs-show' );
}
// after animation ends remove added classes from fields
var self = this,
onEndAnimationFn = function( ev ) {
if( support.animations ) {
this.removeEventListener( animEndEventName, onEndAnimationFn );
}
classie.remove( self.fieldsList, 'fs-display-' + self.navdir );
classie.remove( currentFld, 'fs-hide' );
if( self.isLastStep ) {
// show the complete form and hide the controls
self._hideCtrl( self.ctrlNav );
self._hideCtrl( self.ctrlProgress );
self._hideCtrl( self.ctrlContinue );
self._hideCtrl( self.ctrlFldStatus );
// replace class fs-form-full with fs-form-overview
classie.remove( self.formEl, 'fs-form-full' );
classie.add( self.formEl, 'fs-form-overview' );
classie.add( self.formEl, 'fs-show' );
// callback
self.options.onReview();
}
else {
classie.remove( nextField, 'fs-show' );
if( self.options.ctrlNavPosition ) {
self.ctrlFldStatusCurr.innerHTML = self.ctrlFldStatusNew.innerHTML;
self.ctrlFldStatus.removeChild( self.ctrlFldStatusNew );
classie.remove( self.ctrlFldStatus, 'fs-show-' + self.navdir );
}
}
self.isAnimating = false;
};
if( support.animations ) {
if( this.navdir === ‘next’ ) {
if( this.isLastStep ) {
currentFld.querySelector( ‘.fs-anim-upper’ ).addEventListener( animEndEventName, onEndAnimationFn );
}
else {
nextField.querySelector( ‘.fs-anim-lower’ ).addEventListener( animEndEventName, onEndAnimationFn );
}
}
else {
nextField.querySelector( ‘.fs-anim-upper’ ).addEventListener( animEndEventName, onEndAnimationFn );
}
}
else {
onEndAnimationFn();
}
}