123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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');
- }
- }
- };
|