Skip to content

Commit 061ab38

Browse files
committed
modularize code with setActiveView and getActiveView
1 parent a369bea commit 061ab38

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/multi-step-form.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,35 @@
199199

200200
form.init();
201201

202+
form.getActiveView = function() {
203+
return form.views.filter(function () { return this.style && this.style.display !== '' && this.style.display !== 'none' });
204+
};
205+
206+
form.setActiveView = function(index) {
207+
var view = form.getActiveView();
208+
209+
// var view = (currentView) ? currentView : form.getActiveView();
210+
211+
view.hide();
212+
form.views.eq(index).show();
213+
form.views.eq(index).find(':input').first().focus();
214+
}
215+
202216
form.nextNavButton.click(function () {
203-
//get the view that is currently being displayed
204-
var view = form.views.filter(function () { return this.style && this.style.display !== '' && this.style.display !== 'none' });
217+
var view = form.getActiveView();
205218

206219
if (form.validate(settings.validate).subset(view)) {
207220
var i = form.views.index(view);
208-
view.hide();
209-
form.views.eq(i + 1).show();
210-
form.views.eq(i + 1).find(':input').first().focus();
221+
222+
form.setActiveView(i+1);
211223
}
212224
});
213225

214226
form.backNavButton.click(function () {
215-
//get the view that is currently being displayed
216-
var view = form.views.filter(function () { return this.style && this.style.display !== '' && this.style.display !== 'none' });
217-
227+
var view = form.getActiveView();
218228
var i = form.views.index(view);
219-
view.hide();
220229

221-
form.views.eq(i - 1).show();
222-
form.views.eq(i - 1).find(':input').first().focus();
230+
form.setActiveView(i-1);
223231
});
224232

225233
};

0 commit comments

Comments
 (0)