Skip to content

Commit 1483654

Browse files
jaquerjaquer
authored andcommitted
Run validaton when calling GotoStep. Requires additional parameter: name of div to validate.
Closes #6.
1 parent 89ba9d4 commit 1483654

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

jquery.formtowizard.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
(function($) {
12-
$.fn.formToWizard = function( options, cmdParam1 ) {
12+
$.fn.formToWizard = function( options, cmdParam1, cmdParam2 ) {
1313
// Stop when selector found nothing!
1414
if (this.length == 0) return this;
1515

@@ -87,7 +87,7 @@
8787
initCommands();
8888

8989
if( typeof commands[ cmd ] === 'function' ) {
90-
commands[ cmd ]( cmdParam1 );
90+
commands[ cmd ]( cmdParam1, cmdParam2 );
9191
} else {
9292
throw cmd + ' is invalid command!';
9393
}
@@ -100,17 +100,20 @@
100100
options = $( element ).data( 'options' );
101101

102102
commands = {
103-
GotoStep: function( stepNo ) {
103+
GotoStep: function( stepNo, currentStep ) {
104104
var stepName = "step" + (--stepNo);
105105

106106
if( $( '#' + stepName )[ 0 ] === undefined ) {
107107
throw 'Step No ' + stepNo + ' not found!';
108108
}
109109

110-
if( $( '#' + stepName ).css( 'display' ) === 'none' ) {
111-
$( element ).find( '.stepDetails' ).hide();
112-
$( '#' + stepName ).show();
113-
selectStep( stepNo );
110+
if ( currentStep !== undefined || options.validateBeforeNext(element, $("#" + currentStep)) === true ) {
111+
112+
if( $( '#' + stepName ).css( 'display' ) === 'none' ) {
113+
$( element ).find( '.stepDetails' ).hide();
114+
$( '#' + stepName ).show();
115+
selectStep( stepNo );
116+
}
114117
}
115118
},
116119
NextStep: function() {

0 commit comments

Comments
 (0)