@@ -13,24 +13,28 @@ class Steps {
13
13
this . init ( ) ;
14
14
}
15
15
16
+ stepClick ( e ) {
17
+ e . preventDefault ( ) ;
18
+ const nextStep = $ ( this ) . closest ( 'li' ) . index ( ) ;
19
+ const stepIndex = e . data . self . getStepIndex ( ) ;
20
+ e . data . self . setActiveStep ( stepIndex , nextStep ) ;
21
+ }
22
+
23
+ btnClick ( e ) {
24
+ e . preventDefault ( ) ;
25
+ const statusAction = $ ( this ) . data ( 'direction' ) ;
26
+ e . data . self . setAction ( statusAction ) ;
27
+ }
28
+
16
29
init ( ) {
17
30
this . hook ( 'onInit' ) ;
18
31
const self = this ;
19
32
20
33
// step click event
21
- $ ( this . el ) . find ( this . options . stepSelector ) . on ( 'click' , function ( e ) {
22
- e . preventDefault ( ) ;
23
- const nextStep = $ ( this ) . closest ( 'li' ) . index ( ) ;
24
- const stepIndex = self . getStepIndex ( ) ;
25
- self . setActiveStep ( stepIndex , nextStep ) ;
26
- } ) ;
34
+ $ ( this . el ) . find ( this . options . stepSelector ) . on ( 'click' , { self } , this . stepClick ) ;
27
35
28
36
// button click event
29
- $ ( this . el ) . find ( `${ this . options . footerSelector } ${ this . options . buttonSelector } ` ) . on ( 'click' , function ( e ) {
30
- e . preventDefault ( ) ;
31
- const statusAction = $ ( this ) . data ( 'direction' ) ;
32
- self . setAction ( statusAction ) ;
33
- } ) ;
37
+ $ ( this . el ) . find ( `${ this . options . footerSelector } ${ this . options . buttonSelector } ` ) . on ( 'click' , { self } , this . btnClick ) ;
34
38
35
39
// set default step
36
40
this . setShowStep ( this . options . startAt , '' , this . options . activeClass ) ;
@@ -50,7 +54,8 @@ class Steps {
50
54
}
51
55
52
56
destroy ( ) {
53
- this . el . empty ( ) ;
57
+ $ ( this . el ) . find ( this . options . stepSelector ) . off ( 'click' , this . stepClick ) ;
58
+ $ ( this . el ) . find ( `${ this . options . footerSelector } ${ this . options . buttonSelector } ` ) . off ( 'click' , this . btnClick ) ;
54
59
this . el . removeData ( 'plugin_Steps' ) ;
55
60
this . hook ( 'onDestroy' ) ;
56
61
}
@@ -107,11 +112,16 @@ class Steps {
107
112
if ( currentIndex > newIndex ) {
108
113
for ( let i = currentIndex ; i >= newIndex ; i -= 1 ) {
109
114
const stepDirectionB = this . getStepDirection ( i , newIndex ) ;
110
- this . options . onChange ( i , newIndex , stepDirectionB ) ;
115
+ const validStep = this . options . onChange ( i , newIndex , stepDirectionB ) ;
111
116
this . setShowStep ( i , `${ this . options . doneClass } ${ this . options . activeClass } ${ this . options . errorClass } ` ) ;
112
117
if ( i === newIndex ) {
113
118
this . setShowStep ( i , `${ this . options . doneClass } ${ this . options . errorClass } ` , this . options . activeClass ) ;
114
119
}
120
+ if ( ! validStep ) {
121
+ this . setShowStep ( i , this . options . doneClass , `${ this . options . activeClass } ${ this . options . errorClass } ` ) ;
122
+ this . setFooterBtns ( ) ;
123
+ break ;
124
+ }
115
125
}
116
126
}
117
127
0 commit comments