1jQuery(document).ready(function () { 2 3 jQuery('.wpcf7-form').each(function(){ 4 // Is Repeater Use in form 5 var repeater_count = jQuery(this).find('.uacf7-repeater-count').val(); 6 7 var uacf7_sid = 1; 8 var form_id =jQuery(this).find("input[name=_wpcf7]").val(); 9 var uacf7_next = jQuery(this).find('.uacf7-next[data-form-id="' + form_id + '"]'); 10 var uacf7_prev = jQuery(this).find('.uacf7-prev[data-form-id="' + form_id + '"]'); 11 var uacf7_step = '.uacf7-step-'+form_id; 12 var total_steps = jQuery(uacf7_step, this).length; 13 14 jQuery(uacf7_step, this).each(function () { 15 var $this = jQuery(this); 16 $this.attr('id', form_id+'step-' + uacf7_sid); 17 18 if( uacf7_sid == 1 ) { 19 $this.addClass('step-start'); 20 } 21 22 if( total_steps == uacf7_sid ) { 23 $this.addClass('step-end'); 24 } 25 26 uacf7_sid++; 27 28 }); 29 uacf7_prev.on('click', function (e) { 30 e.preventDefault(); 31 }); 32 33 uacf7_next.on('click', function (e) { 34 e.preventDefault(); 35 36 var $this = jQuery(this); 37 uacf7_step_validation($this, uacf7_step, form_id, repeater_count); 38 }); 39 }); 40 41 42 43 function uacf7_step_validation($this, uacf7_step, form_id, repeater_count) { 44 var uacf7_current_step = jQuery($this).closest(uacf7_step); 45 46 /* 47 * Cheeck current step fields. Expect Checkbox, Radio button and hidden fields 48 */ 49 var uacf7_current_step_fields = uacf7_current_step.find('.wpcf7-form-control:not(.uacf7-hidden .wpcf7-form-control, span.wpcf7-form-control)').map(function () { 50 var nameIndex = this.name.indexOf('[]'); 51 if(nameIndex !== -1){ 52 var fieldName = this.name.replace('[]',''); 53 }else { 54 var fieldName = this.name; 55 } 56 return fieldName; 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 if (jQuery(uacf7_current_step).find(".wpcf7-form-control[type='file']").length > 0 ) { 94 jQuery(uacf7_current_step).find(".wpcf7-form-control[type='file']").each(function (i, n) { 95 fields_to_check_serialized += "&" + jQuery(this).attr('name') + "=" + jQuery(this).val(); 96 if(jQuery(this)[0].files.length > 0){ 97 var file_size = jQuery(this)[0].files[0].size; 98 fields_to_check_serialized += "&" + jQuery(this).attr('name') + "_size=" + file_size; 99 } 100 }); 101 } 102 // console.log( console.log(fields_to_check_serialized)) 103 104 var validation_fields = []; 105 for (let i = 0; i < uacf7_current_step_fields.length; i++) { 106 if(uacf7_current_step_fields[i] != ''){ 107 var type = jQuery("[name="+uacf7_current_step_fields[i]+"]"); 108 if(typeof type[0] === 'undefined' ){ 109 type = jQuery('[name="'+uacf7_current_step_fields[i]+'[]"]'); 110 } 111 type = type[0].localName; 112 // Repeater Validation issue 113 if( typeof repeater_count != 'undefined' ){ 114 var value = jQuery("[name="+uacf7_current_step_fields[i]+"]").val(); 115 var valuecheckbox = jQuery("[name="+uacf7_current_step_fields[i]+"][type='checkbox']"); 116 if(value == '' || valuecheckbox.length > 0){ 117 validation_fields.push( ''+type+':'+uacf7_current_step_fields[i]+'' ); 118 } 119 }else{ 120 validation_fields.push( ''+type+':'+uacf7_current_step_fields[i]+'' ); 121 } 122 } 123 124 } 125 var data = fields_to_check_serialized + 126 '&' + 'action=' + 'check_fields_validation' + 127 '&' + 'form_id=' +form_id+ 128 '&' + 'validation_fields=' +validation_fields+ 129 '&' + 'current_fields_to_check=' + uacf7_current_step_fields + 130 '&' + 'ajax_nonce=' + uacf7_multistep_obj.nonce; 131 jQuery.ajax({ 132 url: uacf7_multistep_obj.ajax_url, 133 type: 'post', 134 dataType: "json", 135 data: data, 136 beforeSend: function(){ 137 138 jQuery($this).closest(".uacf7-step").find('.uacf7-ajax-loader').addClass('is-active'); 139 140 }, 141 success: function (response) { 142 143 jQuery($this).closest(".uacf7-step").find('.uacf7-ajax-loader').removeClass('is-active'); 144 145 var json_result = (typeof response === 'object') ? response : JSON.parse(response); 146 147 var $form = jQuery('form'); 148 clear_error_messages($form, uacf7_current_step); 149 150 try { 151 if (json_result.is_valid) { 152 153 var curStep = jQuery($this).closest(".uacf7-step"), 154 curStepBtn = curStep.attr("id"), 155 nextStepWizard = jQuery('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a"); 156 157 nextStepWizard.removeAttr('disabled').trigger('click'); 158 159 } else { 160 161 // show errors 162 jQuery.each(json_result.invalid_fields, function (i, n) { 163 164 jQuery(n.into, 'form').each(function () { 165 166 jQuery('.wpcf7-form-control', this).addClass('wpcf7-not-valid'); 167 jQuery('[aria-invalid]', this).attr('aria-invalid', 'true'); 168 169 jQuery( this ).append( '<span class="wpcf7-not-valid-tip" aria-hidden="true">'+n.message+'</span>' ); 170 171 }); 172 }); 173 174 } 175 } catch (e) { 176 console.log("error: " + e); 177 } 178 if(typeof uacf7_multistep_scroll !== 'undefined' && uacf7_multistep_scroll.scroll_top == 'on'){ 179 multistep_scroll_to_top($this.parents('form'));
180 } 181 }, 182 error: function () { 183 alert('Error'); 184 } 185 }); 186 } 187 188 function clear_error_messages($form, uacf7_current_step) { 189 $form.removeClass('invalid'); 190 jQuery('.wpcf7-response-output', $form).removeClass('wpcf7-validation-errors'); 191 jQuery('.wpcf7-form-control', uacf7_current_step).removeClass('wpcf7-not-valid'); 192 jQuery('[aria-invalid]', uacf7_current_step).attr('aria-invalid', 'false'); 193 jQuery('.wpcf7-not-valid-tip', uacf7_current_step).remove(); 194 } 195 196 function multistep_scroll_to_top(element){ 197 jQuery([document.documentElement, document.body]).animate({ 198 scrollTop: jQuery(element).offset().top - 120 199 }, 500); 200 } 201 202 function acceptance_validation($this, uacf7_next, uacf7_step){ 203 var $this = $this.closest(uacf7_step); 204 var acceptance = $this.find('.wpcf7-acceptance'); 205 if(acceptance.length == 0){ 206 return false; 207 } 208 acceptance.each(function (){ 209 if(jQuery(this).hasClass('invert')){ 210 var invert = true; 211 }else{ 212 var invert = false; 213 } 214 if(jQuery(this).hasClass('optional')){ 215 var optional = true; 216 }else{ 217 var optional = false; 218 } 219 acceptance_validation_disabled_button($this, invert, optional, uacf7_next, this.checked ); 220 221 jQuery(this).find('input[type="checkbox"]').change(function(){ 222 acceptance_validation_disabled_button($this, invert, optional, uacf7_next, this.checked ); 223 }); 224 225 226 }); 227 } 228 function acceptance_validation_disabled_button($this, invert, optional, uacf7_next, checked){ 229 if(invert == true && checked == false){ 230 var next_disable = false 231 } else if(invert == false && checked == true){ 232 var next_disable = false 233 }else{ 234 var next_disable = true 235 } 236 if(next_disable == true ){ 237 $this.find(uacf7_next).prop("disabled",true) 238 }else{ 239 $this.find(uacf7_next).prop("disabled",false) 240 } 241 if(optional == true){ 242 $this.find(uacf7_next).prop("disabled",false) 243 } 244 } 245 246});
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.