111 lines
2.3 KiB
JavaScript
111 lines
2.3 KiB
JavaScript
require('./idealsteps');
|
|
|
|
module.exports = {
|
|
|
|
name: 'steps',
|
|
|
|
options: {
|
|
stepsContainer: '.idealsteps-container',
|
|
stepsOptions: {}
|
|
},
|
|
|
|
methods: {
|
|
|
|
// @extend
|
|
_init: function() {
|
|
this._buildSteps();
|
|
},
|
|
|
|
// @extend
|
|
_validate: function() {
|
|
|
|
var self = this;
|
|
|
|
this._updateSteps();
|
|
|
|
if ($.idealforms.hasExtension('idealAjax')) {
|
|
$.each($.idealforms._requests, function(key, request) {
|
|
request.done(function(){ self._updateSteps() });
|
|
});
|
|
}
|
|
},
|
|
|
|
// @extend
|
|
focusFirstInvalid: function(firstInvalid) {
|
|
|
|
var self = this;
|
|
|
|
this.$stepsContainer.idealsteps('go', function() {
|
|
return this.$steps.filter(function() {
|
|
return $(this).find(firstInvalid).length;
|
|
}).index();
|
|
});
|
|
},
|
|
|
|
_buildSteps: function() {
|
|
|
|
var self = this, options
|
|
, hasRules = ! $.isEmptyObject(this.opts.rules)
|
|
, counter = hasRules
|
|
? '<span class="counter"/>'
|
|
: '<span class="counter zero">0</span>';
|
|
|
|
options = $.extend({}, {
|
|
buildNavItems: function(i){ return 'Step '+ (i+1) + counter }
|
|
}, this.opts.stepsOptions);
|
|
|
|
this.$stepsContainer = this.$form.closest(this.opts.stepsContainer).idealsteps(options);
|
|
},
|
|
|
|
_updateSteps: function() {
|
|
|
|
var self = this;
|
|
|
|
this.$stepsContainer.idealsteps('_inject', function() {
|
|
|
|
var idealsteps = this;
|
|
|
|
this.$navItems.each(function(i) {
|
|
var invalid = idealsteps.$steps.eq(i).find(self.getInvalid()).length;
|
|
$(this).find('span').text(invalid).toggleClass('zero', ! invalid);
|
|
});
|
|
});
|
|
},
|
|
|
|
// @extend
|
|
addRules: function() {
|
|
this.firstStep();
|
|
},
|
|
|
|
// @extend
|
|
toggleFields: function() {
|
|
this._updateSteps();
|
|
},
|
|
|
|
// @extend
|
|
removeFields: function() {
|
|
this._updateSteps();
|
|
},
|
|
|
|
goToStep: function(idx) {
|
|
this.$stepsContainer.idealsteps('go', idx);
|
|
},
|
|
|
|
prevStep: function() {
|
|
this.$stepsContainer.idealsteps('prev');
|
|
},
|
|
|
|
nextStep: function() {
|
|
this.$stepsContainer.idealsteps('next');
|
|
},
|
|
|
|
firstStep: function() {
|
|
this.$stepsContainer.idealsteps('first');
|
|
},
|
|
|
|
lastStep: function() {
|
|
this.$stepsContainer.idealsteps('last');
|
|
}
|
|
}
|
|
|
|
};
|