PageSourceSearch

https://teacherplus.org/wp-content/plugins/ultimate-addons-for-con…/assets/js/multistep.js?ver=3.5.49

js teacherplus.org collected 2026-09-24 19:58:14 UTC 12,538 bytes, 299 lines download raw bytes

1(function($){
2
3    function initUACF7MultiStep($context) {
4        $context.find('.wpcf7').each(function(){
5            // Is Repeater Use in form
6            var repeater_count = jQuery(this).find('.uacf7-repeater-count').val();
7
8            var uacf7_sid = 1;
9            var form_id = jQuery(this).find("input[name=_wpcf7]").val();
10            var uacf7_next = jQuery(this).find('.uacf7-next[data-form-id="' + form_id + '"]');
11            var uacf7_prev = jQuery(this).find('.uacf7-prev[data-form-id="' + form_id + '"]');
12            var uacf7_step = '.uacf7-step-' + form_id;
13            var total_steps = jQuery(uacf7_step, this).length;
14
15            jQuery(uacf7_step, this).each(function () {
16                var $this = jQuery(this);
17                $this.attr('id', form_id + 'step-' + uacf7_sid);
18                $this.attr('step-id', uacf7_sid);
19
20                if (uacf7_sid == 1) {
21                    $this.addClass('step-start');
22                }
23
24                if (total_steps == uacf7_sid) {
25                    $this.addClass('step-end');
26                }
27
28                uacf7_sid++;
29
30            });
31            uacf7_prev.on('click', function (e) {
32                e.preventDefault();
33            });
34
35            uacf7_next.on('click', function (e) {
36                e.preventDefault();
37
38                var $this = jQuery(this);
39                uacf7_step_validation($this, uacf7_step, form_id, repeater_count);
40            });
41        });
42    }
43
44
45
46    function uacf7_step_validation($this, uacf7_step, form_id, repeater_count) {
47        var uacf7_current_step = jQuery($this).closest(uacf7_step);
48        var uacf7_next_step = 1 + parseInt(uacf7_current_step.attr('step-id'));
49
50        /*
51        * Cheeck current step fields. Expect Checkbox, Radio button and hidden fields
52        */
53        var uacf7_current_step_fields = uacf7_current_step.find('input, select, textarea').filter(function () {
54            return this.offsetParent !== null && this.name;
55        }).map(function () {
56            return this.name.replace(/\[\]$/, '');
57        }).get();
58
59        /*
60        * Cheeck current step fields. Only Checkbox and Radio button
61        */
62        // if (uacf7_current_step.find('.wpcf7-form-control input').length > 0) {
63        //     uacf7_current_step.find('.wpcf7-form-control input').each(function () {
64
65        //         var Value = jQuery('.wpcf7-form-control input[name="' + this.name + '"]:checked').val();
66
67        //         if (jQuery(this).is("input[type='checkbox']")) {
68        //             if (typeof Value == 'undefined') {
69        //                 var checkboxName = this.name.replace('[]', '');
70        //                 uacf7_current_step_fields.push(checkboxName);
71        //             }
72
73        //         } else {
74        //             if (typeof Value == 'undefined') {
75        //                 var checkboxName = this.name;
76        //                 uacf7_current_step_fields.push(checkboxName);
77        //             }
78        //         }
79        //     });
80        // }
81
82        function uacf7_onlyUnique(value, index, self) {
83            return self.indexOf(value) === index;
84        }
85
86        //Current step fields
87        var uacf7_current_step_fields = uacf7_current_step_fields.filter(uacf7_onlyUnique);
88
89        var uacf7_form_ids = '';
90
91        var fields_to_check_serialized = jQuery(uacf7_current_step).find(".wpcf7-form-control").serialize();
92
93        // Manually add selected radio inputs (serialize skips unselected)
94        uacf7_current_step.find('input[type="radio"]').each(function () {
95            var name = this.name;
96            if (fields_to_check_serialized.indexOf(name + '=') === -1) {
97                var checkedVal = jQuery('input[name="' + name + '"]:checked').val();
98                if (typeof checkedVal !== 'undefined') {
99                    fields_to_check_serialized += '&' + encodeURIComponent(name) + '=' + encodeURIComponent(checkedVal);
100                }
101            }
102        });
103
104        // Manually add selected radio and checkbox inputs (serialize skips unselected/multiple)
105        uacf7_current_step.find('input[type="radio"], input[type="checkbox"]').each(function () {
106            var name = this.name;
107            var isChecked = jQuery(this).is(':checked');
108
109            // Skip if already serialized
110            if (fields_to_check_serialized.indexOf(encodeURIComponent(name) + '=') === -1 && isChecked) {
111                var val = jQuery(this).val();
112                fields_to_check_serialized += '&' + encodeURIComponent(name) + '=' + encodeURIComponent(val);
113            }
114        });
115
116        
117
118        if (jQuery(uacf7_current_step).find(".wpcf7-form-control[type='file']").length > 0) {
119            jQuery(uacf7_current_step).find(".wpcf7-form-control[type='file']").each(function (i, n) {
120                fields_to_check_serialized += "&" + jQuery(this).attr('name') + "=" + jQuery(this).val();
121                if (jQuery(this)[0].files.length > 0) {
122                    var file_size = jQuery(this)[0].files[0].size;
123                    fields_to_check_serialized += "&" + jQuery(this).attr('name') + "_size=" + file_size;
124                }
125            });
126        }
127        // console.log( console.log(fields_to_check_serialized))
128
129        var validation_fields = [];
130        for (let i = 0; i < uacf7_current_step_fields.length; i++) {
131            if (uacf7_current_step_fields[i] != '') {
132                var type = jQuery("[name=" + uacf7_current_step_fields[i] + "]");
133                if (typeof type[0] === 'undefined') {
134                    type = jQuery('[name="' + uacf7_current_step_fields[i] + '[]"]');
135                }
136                type = type[0].localName;
137                // Repeater Validation issue 
138                if (typeof repeater_count != 'undefined') {
139                    var value = jQuery("[name=" + uacf7_current_step_fields[i] + "]").val();
140                    var valuecheckbox = jQuery("[name=" + uacf7_current_step_fields[i] + "][type='checkbox']");
141                    if (value == '' || valuecheckbox.length > 0) {
142                        validation_fields.push('' + type + ':' + uacf7_current_step_fields[i] + '');
143                    }
144                } else {
145                    validation_fields.push('' + type + ':' + uacf7_current_step_fields[i] + '');
146                }
147            }
148
149        }
150        // console.log(uacf7_current_step_fields);
151        var data = fields_to_check_serialized +
152            '&' + 'action=' + 'uacf7_check_fields_validation' +
153            '&' + 'form_id=' + form_id +
154            '&' + 'validation_fields=' + validation_fields +
155            '&' + 'current_fields_to_check=' + uacf7_current_step_fields +
156            '&' + 'ajax_nonce=' + uacf7_multistep_obj.nonce;
157        jQuery.ajax({
158            url: uacf7_multistep_obj.ajax_url,
159            type: 'post',
160            dataType: "json",
161            data: data,
162            beforeSend: function () {
163
164                jQuery($this).closest(".uacf7-step").find('.uacf7-ajax-loader').addClass('is-active');
165
166            },
167            success: function (response) {
168
169                jQuery($this).closest(".uacf7-step").find('.uacf7-ajax-loader').removeClass('is-active');
170
171                var json_result = (typeof response === 'object') ? response : JSON.parse(response);
172
173                var $form = jQuery('form');
174                clear_error_messages($form, uacf7_current_step);
175
176                try {
177                    if (json_result.is_valid) {
178
179                        var curStep = jQuery($this).closest(".uacf7-step"),
180                            curStepBtn = curStep.attr("id"),
181                            nextStepWizard = jQuery('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a");
182
183                        // nextStepWizard.removeAttr('disabled').trigger('click');
184                        // nextStepWizard.removeAttr('disabled').trigger('click');
185                        jQuery('.steps-step').find('a[data-form-id="' + form_id + '"]').removeClass('uacf7-btn-active');
186                        uacf7_current_step.hide();
187                        uacf7_current_step.addClass('completed');
188                        jQuery('#' + form_id + 'step-' + uacf7_next_step).show();
189
190                        jQuery('.steps-step').find('a[href="#' + curStepBtn + '"]').addClass('completed');
191                        jQuery('.steps-step').find('a[href="#' + form_id + 'step-' + uacf7_next_step + '"]').addClass('uacf7-btn-active');
192                        jQuery('.steps-step').find('a[href="#' + form_id + 'step-' + uacf7_next_step + '"]').parent().addClass('step-complete');
193
194                        // Hide All steps Title:
195                        jQuery('.current-step-title').find('.step-title').hide();
196                        // Show Next Step Title:
197                        jQuery('.current-step-title').find('.step-title.step-' + uacf7_next_step).show();
198
199                    } else {
200
201                        // show errors
202                        jQuery.each(json_result.invalid_fields, function (i, n) {
203
204                            jQuery(n.into, 'form').each(function () {
205
206                                jQuery('.wpcf7-form-control', this).addClass('wpcf7-not-valid');
207                                jQuery('[aria-invalid]', this).attr('aria-invalid', 'true');
208
209                                jQuery(this).append('<span class="wpcf7-not-valid-tip" aria-hidden="true">' + n.message + '</span>');
210
211                            });
212                        });
213
214                    }
215                } catch (e) {
216                    console.log("error: " + e);
217                }
218                if (typeof uacf7_multistep_scroll !== 'undefined' && uacf7_multistep_scroll.scroll_top == 1) {
219                    multistep_scroll_to_top($this.parents('form'));
220                }
221            },
222            error: function (e) {
223                alert('Error ajax load' + e);
224            }
225        });
226    }
227
228    function clear_error_messages($form, uacf7_current_step) {
229        $form.removeClass('invalid');
230        jQuery('.wpcf7-response-output', $form).removeClass('wpcf7-validation-errors');
231        jQuery('.wpcf7-form-control', uacf7_current_step).removeClass('wpcf7-not-valid');
232        jQuery('[aria-invalid]', uacf7_current_step).attr('aria-invalid', 'false');
233        jQuery('.wpcf7-not-valid-tip', uacf7_current_step).remove();
234    }
235
236    function multistep_scroll_to_top(element) {
237        jQuery([document.documentElement, document.body]).animate({
238            scrollTop: jQuery(element).offset().top - 120
239        }, 500);
240    }
241
242    function acceptance_validation($this, uacf7_next, uacf7_step) {
243        var $this = $this.closest(uacf7_step);
244        var acceptance = $this.find('.wpcf7-acceptance');
245        if (acceptance.length == 0) {
246            return false;
247        }
248        acceptance.each(function () {
249            if (jQuery(this).hasClass('invert')) {
250                var invert = true;
251            } else {
252                var invert = false;
253            }
254            if (jQuery(this).hasClass('optional')) {
255                var optional = true;
256            } else {
257                var optional = false;
258            }
259            acceptance_validation_disabled_button($this, invert, optional, uacf7_next, this.checked);
260
261            jQuery(this).find('input[type="checkbox"]').change(function () {
262                acceptance_validation_disabled_button($this, invert, optional, uacf7_next, this.checked);
263            });
264
265
266        });
267    }
268
269    function acceptance_validation_disabled_button($this, invert, optional, uacf7_next, checked) {
270        if (invert == true && checked == false) {
271            var next_disable = false
272        } else if (invert == false && checked == true) {
273            var next_disable = false
274        } else {
275            var next_disable = true
276        }
277        if (next_disable == true) {
278            $this.find(uacf7_next).prop("disabled", true)
279        } else {
280            $this.find(uacf7_next).prop("disabled", false)
281        }
282        if (optional == true) {
283            $this.find(uacf7_next).prop("disabled", false)
284        }
285    }
286
287
288    // On document ready (first load)
289    $(document).ready(function(){
290        initUACF7MultiStep($(document));
291    });
292
293    // When Elementor popup opens
294    $(document).on('elementor/popup/show', function(event, id, instance){
295        var $popup = $(instance.$element);
296        initUACF7MultiStep($popup);
297    });
298
299})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.