fonts
5 years ago
scripts
5 years ago
styles
5 years ago
global.html
5 years ago
index.html
2 years ago
module-wpcf7cf.html
5 years ago
scripts.js.html
2 years ago
scripts_es6.js.html
4 years ago
wpcf7cf.html
2 years ago
wpcf7cfApi.html
5 years ago
scripts.js.html
1552 lines
| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <title>JSDoc: Source: scripts.js</title> |
| 6 | |
| 7 | <script src="scripts/prettify/prettify.js"> </script> |
| 8 | <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | <!--[if lt IE 9]> |
| 10 | <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | <![endif]--> |
| 12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> |
| 14 | </head> |
| 15 | |
| 16 | <body> |
| 17 | |
| 18 | <div id="main"> |
| 19 | |
| 20 | <h1 class="page-title">Source: scripts.js</h1> |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | <section> |
| 28 | <article> |
| 29 | <pre class="prettyprint source linenums"><code>"use strict"; |
| 30 | |
| 31 | // disable client side validation introduced in CF7 5.6 for now |
| 32 | if (typeof wpcf7 !== 'undefined') { |
| 33 | wpcf7.validate = (a,b) => null; |
| 34 | } |
| 35 | |
| 36 | let cf7signature_resized = 0; // for compatibility with contact-form-7-signature-addon |
| 37 | |
| 38 | let wpcf7cf_timeout; |
| 39 | let wpcf7cf_change_time_ms = 100; // the timeout after a change in the form is detected |
| 40 | |
| 41 | if (window.wpcf7 && !wpcf7.setStatus) { |
| 42 | wpcf7.setStatus = ( form, status ) => { |
| 43 | form = form.length ? form[0] : form; // if form is a jQuery object, only grab te html-element |
| 44 | const defaultStatuses = new Map( [ |
| 45 | // 0: Status in API response, 1: Status in HTML class |
| 46 | [ 'init', 'init' ], |
| 47 | [ 'validation_failed', 'invalid' ], |
| 48 | [ 'acceptance_missing', 'unaccepted' ], |
| 49 | [ 'spam', 'spam' ], |
| 50 | [ 'aborted', 'aborted' ], |
| 51 | [ 'mail_sent', 'sent' ], |
| 52 | [ 'mail_failed', 'failed' ], |
| 53 | [ 'submitting', 'submitting' ], |
| 54 | [ 'resetting', 'resetting' ], |
| 55 | ] ); |
| 56 | |
| 57 | if ( defaultStatuses.has( status ) ) { |
| 58 | status = defaultStatuses.get( status ); |
| 59 | } |
| 60 | |
| 61 | if ( ! Array.from( defaultStatuses.values() ).includes( status ) ) { |
| 62 | status = status.replace( /[^0-9a-z]+/i, ' ' ).trim(); |
| 63 | status = status.replace( /\s+/, '-' ); |
| 64 | status = `custom-${ status }`; |
| 65 | } |
| 66 | |
| 67 | const prevStatus = form.getAttribute( 'data-status' ); |
| 68 | |
| 69 | form.wpcf7.status = status; |
| 70 | form.setAttribute( 'data-status', status ); |
| 71 | form.classList.add( status ); |
| 72 | |
| 73 | if ( prevStatus && prevStatus !== status ) { |
| 74 | form.classList.remove( prevStatus ); |
| 75 | } |
| 76 | |
| 77 | return status; |
| 78 | }; |
| 79 | } |
| 80 | |
| 81 | if (window.wpcf7cf_running_tests) { |
| 82 | jQuery('input[name="_wpcf7cf_options"]').each(function(e) { |
| 83 | const $input = jQuery(this); |
| 84 | const opt = JSON.parse($input.val()); |
| 85 | opt.settings.animation_intime = 0; |
| 86 | opt.settings.animation_outtime = 0; |
| 87 | $input.val(JSON.stringify(opt)); |
| 88 | }); |
| 89 | wpcf7cf_change_time_ms = 0; |
| 90 | } |
| 91 | |
| 92 | const wpcf7cf_show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" }; |
| 93 | const wpcf7cf_hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" }; |
| 94 | |
| 95 | const wpcf7cf_show_step_animation = { "opacity": "show" }; |
| 96 | const wpcf7cf_hide_step_animation = { "opacity": "hide" }; |
| 97 | |
| 98 | const wpcf7cf_change_events = 'input.wpcf7cf paste.wpcf7cf change.wpcf7cf click.wpcf7cf propertychange.wpcf7cf changedisabledprop.wpcf7cf'; |
| 99 | |
| 100 | const wpcf7cf_forms = []; |
| 101 | |
| 102 | const Wpcf7cfForm = function($form) { |
| 103 | |
| 104 | const options_element = $form.find('input[name="_wpcf7cf_options"]').eq(0); |
| 105 | if (!options_element.length || !options_element.val()) { |
| 106 | // doesn't look like a CF7 form created with conditional fields plugin enabled. |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | const form = this; |
| 111 | |
| 112 | const form_options = JSON.parse(options_element.val()); |
| 113 | |
| 114 | form.$form = $form; |
| 115 | form.$input_hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]'); |
| 116 | form.$input_hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]'); |
| 117 | form.$input_visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]'); |
| 118 | form.$input_repeaters = $form.find('[name="_wpcf7cf_repeaters"]'); |
| 119 | form.$input_steps = $form.find('[name="_wpcf7cf_steps"]'); |
| 120 | |
| 121 | form.unit_tag = $form.closest('.wpcf7').attr('id'); |
| 122 | form.conditions = form_options['conditions']; |
| 123 | |
| 124 | form.simpleDom = null; |
| 125 | |
| 126 | form.reloadSimpleDom = function() { |
| 127 | form.simpleDom = wpcf7cf.get_simplified_dom_model(form.$form[0]); |
| 128 | } |
| 129 | |
| 130 | // quicker than reloading the simpleDom completely with reloadSimpleDom |
| 131 | form.updateSimpleDom = function() { |
| 132 | if (!form.simpleDom) { |
| 133 | form.reloadSimpleDom(); |
| 134 | } |
| 135 | const inputs = Object.values(form.simpleDom).filter(item => item.type === 'input'); |
| 136 | const formdata = new FormData(form.$form[0]); |
| 137 | |
| 138 | let formdataEntries = [... formdata.entries()].map(entry => [ entry[0], entry[1].name ?? entry[1] ]); |
| 139 | const buttonEntries = [ ... jQuery('button', form.$form) ].map(entry => [entry.name, entry.value]); |
| 140 | formdataEntries = formdataEntries.concat(buttonEntries); |
| 141 | |
| 142 | inputs.forEach(simpleDomItem => { |
| 143 | const newValue = form.getNewDomValueIfChanged(simpleDomItem, formdataEntries); |
| 144 | if (newValue !== null) { |
| 145 | form.simpleDom[simpleDomItem.name].val = newValue; |
| 146 | } |
| 147 | }); |
| 148 | |
| 149 | } |
| 150 | |
| 151 | form.isDomMatch = function(simpleDomItem, formDataEntries) { |
| 152 | const simpleDomItemName = simpleDomItem.name; |
| 153 | const simpleDomItemValues = simpleDomItem.val; |
| 154 | const currentValues = formDataEntries.filter(entry => entry[0] === simpleDomItemName).map(entry => entry[1]); |
| 155 | return currentValues.join('|') === simpleDomItemValues.join('|'); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * |
| 160 | * @param {*} simpleDomItem |
| 161 | * @param {*} formDataEntries |
| 162 | * @returns the new value, or NULL if no change |
| 163 | */ |
| 164 | form.getNewDomValueIfChanged = function(simpleDomItem, formDataEntries) { |
| 165 | const simpleDomItemName = simpleDomItem.name; |
| 166 | const simpleDomItemValues = simpleDomItem.val; |
| 167 | const currentValues = formDataEntries.filter(entry => entry[0] === simpleDomItemName).map(entry => entry[1]); |
| 168 | return currentValues.join('|') === simpleDomItemValues.join('|') ? null : currentValues; |
| 169 | } |
| 170 | |
| 171 | // Wrapper around jQuery(selector, form.$form) |
| 172 | form.get = function (selector) { |
| 173 | // TODO: implement some caching here. |
| 174 | return jQuery(selector, form.$form); |
| 175 | } |
| 176 | |
| 177 | form.getFieldByName = function(name) { |
| 178 | return form.simpleDom[name] || form.simpleDom[name+'[]']; |
| 179 | } |
| 180 | |
| 181 | // compatibility with conditional forms created with older versions of the plugin ( < 1.4 ) |
| 182 | for (let i=0; i < form.conditions.length; i++) { |
| 183 | const condition = form.conditions[i]; |
| 184 | if (!('and_rules' in condition)) { |
| 185 | condition.and_rules = [{'if_field':condition.if_field,'if_value':condition.if_value,'operator':condition.operator}]; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | form.initial_conditions = form.conditions; |
| 190 | form.settings = form_options['settings']; |
| 191 | |
| 192 | form.$groups = jQuery(); // empty jQuery set |
| 193 | form.repeaters = []; |
| 194 | form.multistep = null; |
| 195 | form.fields = []; |
| 196 | |
| 197 | form.settings.animation_intime = parseInt(form.settings.animation_intime); |
| 198 | form.settings.animation_outtime = parseInt(form.settings.animation_outtime); |
| 199 | |
| 200 | if (form.settings.animation === 'no') { |
| 201 | form.settings.animation_intime = 0; |
| 202 | form.settings.animation_outtime = 0; |
| 203 | } |
| 204 | |
| 205 | form.updateGroups(); |
| 206 | form.updateEventListeners(); |
| 207 | form.displayFields(); |
| 208 | |
| 209 | // bring form in initial state if the reset event is fired on it. |
| 210 | // (CF7 triggers the 'reset' event by default on each successfully submitted form) |
| 211 | form.$form.on('reset.wpcf7cf', form, function(e) { |
| 212 | const form = e.data; |
| 213 | setTimeout(function(){ |
| 214 | form.reloadSimpleDom(); |
| 215 | form.displayFields(); |
| 216 | form.resetRepeaters(); |
| 217 | if (form.multistep != null) { |
| 218 | form.multistep.moveToStep(1, false); |
| 219 | } |
| 220 | setTimeout(function(){ |
| 221 | if (form.$form.hasClass('sent')) { |
| 222 | jQuery('.wpcf7-response-output', form.$form)[0].scrollIntoView({behavior: "smooth", block:"nearest", inline:"nearest"}); |
| 223 | } |
| 224 | }, 400); |
| 225 | },200); |
| 226 | }); |
| 227 | |
| 228 | // PRO ONLY |
| 229 | |
| 230 | form.get('.wpcf7cf_repeater:not(.wpcf7cf_repeater .wpcf7cf_repeater)').each(function(){ |
| 231 | form.repeaters.push(new Wpcf7cfRepeater(jQuery(this),form)); |
| 232 | }); |
| 233 | |
| 234 | form.$input_repeaters.val(JSON.stringify(form.repeaters.map((item)=>item.params.$repeater.id))); |
| 235 | |
| 236 | const $multistep = form.get('.wpcf7cf_multistep'); |
| 237 | |
| 238 | if ($multistep.length) { |
| 239 | form.multistep = new Wpcf7cfMultistep($multistep, form); |
| 240 | // window.wpcf7cf.updateMultistepState(form.multistep); |
| 241 | } |
| 242 | |
| 243 | // END PRO ONLY |
| 244 | |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * reset initial number of subs for each repeater. |
| 249 | * (does not clear values) |
| 250 | */ |
| 251 | Wpcf7cfForm.prototype.resetRepeaters = function() { |
| 252 | const form = this; |
| 253 | form.repeaters.forEach(repeater => { |
| 254 | repeater.updateSubs( repeater.params.$repeater.initial_subs ); |
| 255 | }); |
| 256 | } |
| 257 | |
| 258 | Wpcf7cfForm.prototype.displayFields = function() { |
| 259 | |
| 260 | const form = this; |
| 261 | |
| 262 | const wpcf7cf_conditions = this.conditions; |
| 263 | const wpcf7cf_settings = this.settings; |
| 264 | |
| 265 | //for compatibility with contact-form-7-signature-addon |
| 266 | if (cf7signature_resized === 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) { |
| 267 | for (let i = 0; i < signatures.length; i++) { |
| 268 | if (signatures[i].canvas.width === 0) { |
| 269 | |
| 270 | const $sig_canvas = jQuery(".wpcf7-form-control-signature-body>canvas"); |
| 271 | const $sig_wrap = jQuery(".wpcf7-form-control-signature-wrap"); |
| 272 | $sig_canvas.eq(i).attr('width', $sig_wrap.width()); |
| 273 | $sig_canvas.eq(i).attr('height', $sig_wrap.height()); |
| 274 | |
| 275 | cf7signature_resized = 1; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | form.$groups.addClass('wpcf7cf-hidden'); |
| 281 | |
| 282 | for (let i=0; i < wpcf7cf_conditions.length; i++) { |
| 283 | |
| 284 | const condition = wpcf7cf_conditions[i]; |
| 285 | |
| 286 | const show_group = window.wpcf7cf.should_group_be_shown(condition, form); |
| 287 | |
| 288 | if (show_group) { |
| 289 | form.get('[data-id="'+condition.then_field+'"]').removeClass('wpcf7cf-hidden'); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
| 294 | const animation_intime = wpcf7cf_settings.animation_intime; |
| 295 | const animation_outtime = wpcf7cf_settings.animation_outtime; |
| 296 | |
| 297 | form.$groups.each(function (index) { |
| 298 | const $group = jQuery(this); |
| 299 | if ($group.is(':animated')) { |
| 300 | $group.finish(); // stop any current animations on the group |
| 301 | } |
| 302 | if ($group.css('display') === 'none' && !$group.hasClass('wpcf7cf-hidden')) { |
| 303 | if ($group.prop('tagName') === 'SPAN') { |
| 304 | $group.show().trigger('wpcf7cf_show_group'); // show instantly |
| 305 | } else { |
| 306 | $group.animate(wpcf7cf_show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show with animation |
| 307 | } |
| 308 | |
| 309 | if($group.attr('data-disable_on_hide') !== undefined) { |
| 310 | $group.find(':input').prop('disabled', false).trigger('changedisabledprop.wpcf7cf'); |
| 311 | $group.find('.wpcf7-form-control-wrap').removeClass('wpcf7cf-disabled'); |
| 312 | } |
| 313 | |
| 314 | } else if ($group.css('display') !== 'none' && $group.hasClass('wpcf7cf-hidden')) { |
| 315 | |
| 316 | if ($group.attr('data-clear_on_hide') !== undefined) { |
| 317 | const $inputs = jQuery(':input', $group).not(':button, :submit, :reset, :hidden'); |
| 318 | |
| 319 | $inputs.each(function(){ |
| 320 | const $this = jQuery(this); |
| 321 | $this.val(this.defaultValue); |
| 322 | $this.prop('checked', this.defaultChecked); |
| 323 | }); |
| 324 | |
| 325 | jQuery('option', $group).each(function() { |
| 326 | this.selected = this.defaultSelected; |
| 327 | }); |
| 328 | |
| 329 | jQuery('select', $group).each(function() { |
| 330 | const $select = jQuery(this); |
| 331 | if ($select.val() === null) { |
| 332 | $select.val(jQuery("option:first",$select).val()); |
| 333 | } |
| 334 | }); |
| 335 | |
| 336 | $inputs.each(function(){this.dispatchEvent(new Event("change",{"bubbles":true}))}); |
| 337 | } |
| 338 | |
| 339 | if ($group.prop('tagName') === 'SPAN') { |
| 340 | $group.hide().trigger('wpcf7cf_hide_group'); |
| 341 | } else { |
| 342 | $group.animate(wpcf7cf_hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide |
| 343 | } |
| 344 | } |
| 345 | }); |
| 346 | |
| 347 | form.updateHiddenFields(); |
| 348 | form.updateSummaryFields(); |
| 349 | }; |
| 350 | |
| 351 | Wpcf7cfForm.prototype.updateSummaryFields = function() { |
| 352 | const form = this; |
| 353 | const $summary = form.get('.wpcf7cf-summary'); |
| 354 | |
| 355 | if ($summary.length == 0 || !$summary.is(':visible')) { |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | const fd = new FormData(); |
| 360 | |
| 361 | const formdata = form.$form.serializeArray(); |
| 362 | jQuery.each(formdata,function(key, input){ |
| 363 | fd.append(input.name, input.value); |
| 364 | }); |
| 365 | |
| 366 | // Make sure to add file fields to FormData |
| 367 | jQuery.each(form.$form.find('input[type="file"]'), function(index, el) { |
| 368 | if (! el.files.length) return true; // continue |
| 369 | const fieldName = el.name; |
| 370 | fd.append(fieldName, new Blob() , Array.from(el.files).map(file => file.name).join(', ')); |
| 371 | }); |
| 372 | |
| 373 | // add file fields to form-data |
| 374 | |
| 375 | jQuery.ajax({ |
| 376 | url: wpcf7cf_global_settings.ajaxurl + '?action=wpcf7cf_get_summary', |
| 377 | type: 'POST', |
| 378 | data: fd, |
| 379 | processData: false, |
| 380 | contentType: false, |
| 381 | dataType: 'json', |
| 382 | success: function(json) { |
| 383 | $summary.html(json.summaryHtml); |
| 384 | } |
| 385 | }); |
| 386 | }; |
| 387 | |
| 388 | Wpcf7cfForm.prototype.updateHiddenFields = function() { |
| 389 | |
| 390 | const form = this; |
| 391 | |
| 392 | const hidden_fields = []; |
| 393 | const hidden_groups = []; |
| 394 | const visible_groups = []; |
| 395 | |
| 396 | form.$groups.each(function () { |
| 397 | const $group = jQuery(this); |
| 398 | if ($group.hasClass('wpcf7cf-hidden')) { |
| 399 | hidden_groups.push($group.attr('data-id')); |
| 400 | if($group.attr('data-disable_on_hide') !== undefined) { |
| 401 | // fields inside hidden disable_on_hide group |
| 402 | $group.find('input,select,textarea').each(function(){ |
| 403 | const $this = jQuery(this); |
| 404 | if (!$this.prop('disabled')) { |
| 405 | $this.prop('disabled', true).trigger('changedisabledprop.wpcf7cf'); |
| 406 | } |
| 407 | |
| 408 | // if there's no other field with the same name visible in the form |
| 409 | // then push this field to hidden_fields |
| 410 | if (form.$form.find(`[data-class="wpcf7cf_group"]:not(.wpcf7cf-hidden) [name='${$this.attr('name')}']`).length === 0) { |
| 411 | hidden_fields.push($this.attr('name')); |
| 412 | } |
| 413 | }) |
| 414 | $group.find('.wpcf7-form-control-wrap').addClass('wpcf7cf-disabled'); |
| 415 | } else { |
| 416 | // fields inside regular hidden group are all pushed to hidden_fields |
| 417 | $group.find('input,select,textarea').each(function () { |
| 418 | hidden_fields.push(jQuery(this).attr('name')); |
| 419 | }); |
| 420 | } |
| 421 | } else { |
| 422 | visible_groups.push($group.attr('data-id')); |
| 423 | } |
| 424 | }); |
| 425 | |
| 426 | form.hidden_fields = hidden_fields; |
| 427 | form.hidden_groups = hidden_groups; |
| 428 | form.visible_groups = visible_groups; |
| 429 | |
| 430 | form.$input_hidden_group_fields.val(JSON.stringify(hidden_fields)); |
| 431 | form.$input_hidden_groups.val(JSON.stringify(hidden_groups)); |
| 432 | form.$input_visible_groups.val(JSON.stringify(visible_groups)); |
| 433 | |
| 434 | return true; |
| 435 | }; |
| 436 | Wpcf7cfForm.prototype.updateGroups = function() { |
| 437 | const form = this; |
| 438 | form.$groups = form.$form.find('[data-class="wpcf7cf_group"]'); |
| 439 | form.$groups.height('auto'); |
| 440 | form.conditions = window.wpcf7cf.get_nested_conditions(form); |
| 441 | |
| 442 | }; |
| 443 | Wpcf7cfForm.prototype.updateEventListeners = function() { |
| 444 | |
| 445 | const form = this; |
| 446 | |
| 447 | // monitor input changes, and call displayFields() if something has changed |
| 448 | form.get('input, select, textarea, button').not('.wpcf7cf_add, .wpcf7cf_remove').off(wpcf7cf_change_events).on(wpcf7cf_change_events,form, function(e) { |
| 449 | const form = e.data; |
| 450 | clearTimeout(wpcf7cf_timeout); |
| 451 | wpcf7cf_timeout = setTimeout(function() { |
| 452 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 453 | form.updateSimpleDom(); |
| 454 | form.displayFields(); |
| 455 | }, wpcf7cf_change_time_ms); |
| 456 | }); |
| 457 | |
| 458 | // PRO ONLY |
| 459 | form.get('.wpcf7cf-togglebutton').off('click.toggle_wpcf7cf').on('click.toggle_wpcf7cf',function() { |
| 460 | const $this = jQuery(this); |
| 461 | if ($this.text() === $this.attr('data-val-1')) { |
| 462 | $this.text($this.attr('data-val-2')); |
| 463 | $this.val($this.attr('data-val-2')); |
| 464 | } else { |
| 465 | $this.text($this.attr('data-val-1')); |
| 466 | $this.val($this.attr('data-val-1')); |
| 467 | } |
| 468 | }); |
| 469 | // END PRO ONLY |
| 470 | }; |
| 471 | |
| 472 | // PRO ONLY |
| 473 | function Wpcf7cfRepeater($repeater, form) { |
| 474 | const $ = jQuery; |
| 475 | |
| 476 | let thisRepeater = this; |
| 477 | |
| 478 | const wpcf7cf_settings = form.settings; |
| 479 | |
| 480 | thisRepeater.form = form; |
| 481 | |
| 482 | $repeater.parentRepeaters = Array.from($repeater.parents('.wpcf7cf_repeater').map(function() { |
| 483 | return this.getAttribute('data-id'); |
| 484 | } )).reverse(); |
| 485 | |
| 486 | $repeater.num_subs = 0; |
| 487 | $repeater.id = $repeater.attr('data-id'); |
| 488 | $repeater.orig_id = $repeater.attr('data-orig_data_id'); |
| 489 | $repeater.min = typeof( $repeater.attr('data-min')) !== 'undefined' ? parseInt($repeater.attr('data-min')) : 1; |
| 490 | $repeater.max = typeof( $repeater.attr('data-max')) !== 'undefined' ? parseInt($repeater.attr('data-max')) : 200; |
| 491 | $repeater.initial_subs = typeof( $repeater.attr('data-initial')) !== 'undefined' ? parseInt($repeater.attr('data-initial')) : $repeater.min; |
| 492 | if ($repeater.initial_subs > $repeater.max) { |
| 493 | $repeater.initial_subs = $repeater.max; |
| 494 | } |
| 495 | const $repeater_sub = $repeater.children('.wpcf7cf_repeater_sub').eq(0); |
| 496 | const $repeater_controls = $repeater.children('.wpcf7cf_repeater_controls').eq(0); |
| 497 | |
| 498 | const $repeater_sub_clone = $repeater_sub.clone(); |
| 499 | |
| 500 | $repeater_sub_clone.find('.wpcf7cf_repeater_sub').addBack('.wpcf7cf_repeater_sub').each(function() { |
| 501 | const $this = jQuery(this); |
| 502 | const prev_suffix = $this.attr('data-repeater_sub_suffix'); |
| 503 | const new_suffix = prev_suffix+'__{{repeater_sub_suffix}}'; |
| 504 | $this.attr('data-repeater_sub_suffix', new_suffix); |
| 505 | }); |
| 506 | |
| 507 | $repeater_sub_clone.find('[name]').each(function() { |
| 508 | const $this = jQuery(this); |
| 509 | const prev_name = $this.attr('name'); |
| 510 | const new_name = thisRepeater.getNewName(prev_name); |
| 511 | |
| 512 | const orig_name = $this.attr('data-orig_name') != null ? $this.attr('data-orig_name') : prev_name; |
| 513 | |
| 514 | $this.attr('name', new_name); |
| 515 | $this.attr('data-orig_name', orig_name); |
| 516 | $this.closest('.wpcf7-form-control-wrap').attr('data-name', new_name.replace('[]','')); |
| 517 | }); |
| 518 | |
| 519 | $repeater_sub_clone.find('.wpcf7cf_repeater,[data-class="wpcf7cf_group"]').each(function() { |
| 520 | const $this = jQuery(this); |
| 521 | const prev_data_id = $this.attr('data-id'); |
| 522 | const orig_data_id = $this.attr('data-orig_data_id') != null ? $this.attr('data-orig_data_id') : prev_data_id; |
| 523 | let new_data_id = thisRepeater.getNewName(prev_data_id); |
| 524 | |
| 525 | if(prev_data_id.endsWith('_count')) { |
| 526 | new_data_id = prev_data_id.replace('_count','__{{repeater_sub_suffix}}_count'); |
| 527 | } |
| 528 | |
| 529 | $this.attr('data-id', new_data_id); |
| 530 | $this.attr('data-orig_data_id', orig_data_id); |
| 531 | }); |
| 532 | |
| 533 | $repeater_sub_clone.find('[id]').each(function() { |
| 534 | const $this = jQuery(this); |
| 535 | const prev_id = $this.attr('id'); |
| 536 | const orig_id = $this.attr('data-orig_id') != null ? $this.attr('data-orig_id') : prev_id; |
| 537 | const new_id = thisRepeater.getNewName(prev_id); |
| 538 | |
| 539 | $this.attr('id', new_id); |
| 540 | $this.attr('data-orig_id', orig_id); |
| 541 | }); |
| 542 | |
| 543 | $repeater_sub_clone.find('[for]').each(function() { |
| 544 | const $this = jQuery(this); |
| 545 | const prev_for = $this.attr('for'); |
| 546 | const orig_for = $this.attr('data-orig_for') != null ? $this.attr('data-orig_for') : prev_for; |
| 547 | const new_for = thisRepeater.getNewName(prev_for); |
| 548 | |
| 549 | $this.attr('for', new_for); |
| 550 | $this.attr('data-orig_for', orig_for); |
| 551 | }); |
| 552 | |
| 553 | const repeater_sub_html = $repeater_sub_clone[0].outerHTML; |
| 554 | |
| 555 | const $repeater_count_field = $repeater.find('[name='+$repeater.id+'_count]').eq(0); |
| 556 | const $button_add = $repeater_controls.find('.wpcf7cf_add').eq(0); |
| 557 | const $button_remove = $repeater_controls.find('.wpcf7cf_remove').eq(0); |
| 558 | |
| 559 | const params = { |
| 560 | $repeater: $repeater, |
| 561 | $repeater_count_field: $repeater_count_field, |
| 562 | repeater_sub_html: repeater_sub_html, |
| 563 | $repeater_controls: $repeater_controls, |
| 564 | $button_add: $button_add, |
| 565 | $button_remove: $button_remove, |
| 566 | wpcf7cf_settings: wpcf7cf_settings |
| 567 | }; |
| 568 | |
| 569 | thisRepeater.params = params; |
| 570 | |
| 571 | $button_add.on('click', null, thisRepeater, function(e) { |
| 572 | thisRepeater = e.data; |
| 573 | thisRepeater.updateSubs(params.$repeater.num_subs+1); |
| 574 | }); |
| 575 | |
| 576 | $button_remove.on('click', null, thisRepeater,function(e) { |
| 577 | thisRepeater = e.data; |
| 578 | thisRepeater.updateSubs(params.$repeater.num_subs-1); |
| 579 | }); |
| 580 | |
| 581 | jQuery('> .wpcf7cf_repeater_sub',params.$repeater).eq(0).remove(); // remove the first sub, it's just a template. |
| 582 | |
| 583 | thisRepeater.updateSubs($repeater.initial_subs); |
| 584 | thisRepeater.updateButtons(); |
| 585 | |
| 586 | } |
| 587 | |
| 588 | Wpcf7cfRepeater.prototype.getNewName = function(previousName) { |
| 589 | const prev_parts = previousName.split('['); |
| 590 | previousName = prev_parts[0]; |
| 591 | const prev_suff = prev_parts.length > 1 ? '['+prev_parts.splice(1).join('[') : ''; |
| 592 | let newName = previousName+'__{{repeater_sub_suffix}}'+prev_suff; |
| 593 | |
| 594 | if(previousName.endsWith('_count')) { |
| 595 | newName = previousName.replace('_count','__{{repeater_sub_suffix}}_count'); |
| 596 | } |
| 597 | |
| 598 | return newName; |
| 599 | } |
| 600 | |
| 601 | Wpcf7cfRepeater.prototype.updateButtons = function() { |
| 602 | const repeater = this; |
| 603 | const params = repeater.params; |
| 604 | const num_subs = params.$repeater.num_subs; |
| 605 | |
| 606 | let showButtonRemove = false; |
| 607 | let showButtonAdd = false; |
| 608 | |
| 609 | if (params.$repeater.num_subs < params.$repeater.max) { |
| 610 | showButtonAdd = true; |
| 611 | } |
| 612 | if (params.$repeater.num_subs > params.$repeater.min) { |
| 613 | showButtonRemove = true; |
| 614 | } |
| 615 | |
| 616 | if (showButtonAdd) { |
| 617 | params.$button_add.show(); |
| 618 | } else { |
| 619 | params.$button_add.hide(); |
| 620 | |
| 621 | } |
| 622 | |
| 623 | if (showButtonRemove) { |
| 624 | params.$button_remove.show(); |
| 625 | } else { |
| 626 | params.$button_remove.hide(); |
| 627 | } |
| 628 | |
| 629 | params.$repeater_count_field.val(num_subs); |
| 630 | } |
| 631 | |
| 632 | Wpcf7cfRepeater.prototype.updateSubs = function(subs_to_show) { |
| 633 | const repeater = this; |
| 634 | const params = repeater.params; |
| 635 | |
| 636 | // make sure subs_to_show is a valid number |
| 637 | subs_to_show = subs_to_show < params.$repeater.min ? params.$repeater.min : subs_to_show |
| 638 | subs_to_show = subs_to_show > params.$repeater.max ? params.$repeater.max : subs_to_show |
| 639 | |
| 640 | const subs_to_add = subs_to_show - params.$repeater.num_subs; |
| 641 | |
| 642 | if (subs_to_add < 0) { |
| 643 | repeater.removeSubs(-subs_to_add); |
| 644 | } else if (subs_to_add > 0) { |
| 645 | repeater.addSubs(subs_to_add); |
| 646 | } |
| 647 | }; |
| 648 | /** |
| 649 | * add Subs to repeater |
| 650 | * @param {Number} subs_to_add |
| 651 | * @param {Number} index - zero-based. leave blank (or null) to append at the end |
| 652 | */ |
| 653 | Wpcf7cfRepeater.prototype.addSubs = function(subs_to_add, index=null) { |
| 654 | |
| 655 | const $ = jQuery; |
| 656 | const params = this.params; |
| 657 | const repeater = this; |
| 658 | const form = repeater.form; |
| 659 | |
| 660 | const $repeater = params.$repeater; |
| 661 | const $repeater_controls = params.$repeater_controls; |
| 662 | |
| 663 | if (subs_to_add + $repeater.num_subs > $repeater.max) { |
| 664 | subs_to_add = $repeater.max - $repeater.num_subs; |
| 665 | } |
| 666 | |
| 667 | let html_str = ''; |
| 668 | |
| 669 | for(let i=1; i<=subs_to_add; i++) { |
| 670 | const sub_suffix = $repeater.num_subs+i; |
| 671 | html_str += params.repeater_sub_html.replace(/\{\{repeater_sub_suffix\}\}/g,sub_suffix) |
| 672 | .replace(new RegExp('\{\{'+$repeater.orig_id+'_index\}\}','g'),'<span class="wpcf7cf-index wpcf7cf__'+$repeater.orig_id+'">'+sub_suffix+'</span>'); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | const $html = $(html_str); |
| 677 | |
| 678 | $('> .wpcf7cf_repeater_sub',$repeater).finish(); // finish any currently running animations immediately. |
| 679 | |
| 680 | // Add the newly created fields to the form |
| 681 | if (index === null) { |
| 682 | $html.hide().insertBefore($repeater_controls).animate(wpcf7cf_show_animation, params.wpcf7cf_settings.animation_intime).trigger('wpcf7cf_repeater_added'); |
| 683 | } else { |
| 684 | $html.hide().insertBefore($('> .wpcf7cf_repeater_sub', $repeater).eq(index)).animate(wpcf7cf_show_animation, params.wpcf7cf_settings.animation_intime).trigger('wpcf7cf_repeater_added'); |
| 685 | } |
| 686 | |
| 687 | // enable all new fields |
| 688 | $html.find('.wpcf7cf-disabled :input').prop('disabled', false).trigger('changedisabledprop.wpcf7cf'); |
| 689 | $html.find('.wpcf7-form-control-wrap').removeClass('wpcf7cf-disabled'); |
| 690 | |
| 691 | $('.wpcf7cf_repeater', $html).each(function(){ |
| 692 | form.repeaters.push(new Wpcf7cfRepeater($(this),form)); |
| 693 | }); |
| 694 | |
| 695 | form.$input_repeaters.val(JSON.stringify(form.repeaters.map((item)=>item.params.$repeater.id))); |
| 696 | |
| 697 | $repeater.num_subs+= subs_to_add; |
| 698 | |
| 699 | if (index !== null) { |
| 700 | repeater.updateSuffixes(); |
| 701 | } |
| 702 | |
| 703 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 704 | form.updateGroups(); |
| 705 | form.updateEventListeners(); |
| 706 | form.displayFields(); |
| 707 | |
| 708 | repeater.updateButtons(); |
| 709 | |
| 710 | // Exclusive Checkbox |
| 711 | $html.on( 'click', '.wpcf7-exclusive-checkbox input:checkbox', function() { |
| 712 | const name = $( this ).attr( 'name' ); |
| 713 | $html.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false ); |
| 714 | } ); |
| 715 | |
| 716 | //basic compatibility with material-design-for-contact-form-7 |
| 717 | if (typeof window.cf7mdInit === "function") { |
| 718 | window.cf7mdInit(); |
| 719 | } |
| 720 | |
| 721 | return false; |
| 722 | }; |
| 723 | |
| 724 | Wpcf7cfRepeater.prototype.updateSuffixes = function() { |
| 725 | |
| 726 | // Loop trough all subs |
| 727 | // -- 1. update all fields, groups and repeaters names, id's, for's, ... |
| 728 | // -- 2. loop trough all repeaters |
| 729 | // -- update sub_html template for nested repeater |
| 730 | // -- call updateSuffixes() for nested repeater |
| 731 | |
| 732 | const $repeater = this.params.$repeater; |
| 733 | const num_subs = this.params.$repeater.num_subs; |
| 734 | const form = this.form; |
| 735 | const orig_id = $repeater.attr('data-orig_data_id'); |
| 736 | const repeater_id = $repeater.attr('data-id'); |
| 737 | const repeater_suffix = repeater_id.replace(orig_id,''); |
| 738 | |
| 739 | let simplifiedDomArray = Object.values(wpcf7cf.get_simplified_dom_model(form.$form[0])); |
| 740 | |
| 741 | for (let i = 0; i < num_subs; i++) { |
| 742 | |
| 743 | const $sub = jQuery('> .wpcf7cf_repeater_sub', $repeater).eq(i); |
| 744 | |
| 745 | const newIndex = i+1; |
| 746 | const currentSuffix = $sub.attr('data-repeater_sub_suffix'); |
| 747 | const newSuffix = repeater_suffix+'__'+newIndex; |
| 748 | |
| 749 | $sub.attr('data-repeater_sub_suffix', newSuffix); // update sub attr |
| 750 | $sub.find('.wpcf7cf__'+orig_id).html(newIndex); // update {{r_index}} parts |
| 751 | |
| 752 | simplifiedDomArray.forEach(function(el) { |
| 753 | |
| 754 | if (el.suffix !== currentSuffix) return; |
| 755 | |
| 756 | // TODO: may need an extra check to verify that the element is inside the current repeater |
| 757 | // (orig_id) . Otherwise problems may occur if there are repeaters on the same level. |
| 758 | |
| 759 | const newName = el.name.replace(currentSuffix, newSuffix); |
| 760 | |
| 761 | const pureElName = el.name.replace('[]',''); |
| 762 | const pureNewName = newName.replace('[]',''); |
| 763 | |
| 764 | jQuery('[name="'+el.name+'"]', $sub).attr('name', newName); |
| 765 | jQuery('[id="'+el.name+'"]', $sub).attr('id', newName); |
| 766 | jQuery('label[for="'+el.name+'"]', $sub).attr('for', newName); |
| 767 | const $nested_repeater = jQuery('[data-id="'+el.name+'"]', $sub); |
| 768 | $nested_repeater.attr('data-id', newName); |
| 769 | jQuery(`.wpcf7-form-control-wrap[data-name="${pureElName}"]`,$sub).attr('data-name', pureNewName); |
| 770 | |
| 771 | if (el.type === 'repeater') { |
| 772 | const nested_repeater = form.repeaters.find( function(repeater) { |
| 773 | return repeater.params.$repeater.get(0) === $nested_repeater.get(0); |
| 774 | }); |
| 775 | |
| 776 | if (!nested_repeater) return; |
| 777 | |
| 778 | nested_repeater.params.repeater_sub_html = wpcf7cf.updateRepeaterSubHTML( |
| 779 | nested_repeater.params.repeater_sub_html, |
| 780 | currentSuffix, |
| 781 | newSuffix, |
| 782 | nested_repeater.params.$repeater.parentRepeaters |
| 783 | ); |
| 784 | |
| 785 | nested_repeater.updateSuffixes(); |
| 786 | |
| 787 | } |
| 788 | |
| 789 | }); |
| 790 | } |
| 791 | |
| 792 | }; |
| 793 | |
| 794 | /** |
| 795 | * Return the parent repeaters, order is not guaranteed. |
| 796 | */ |
| 797 | Wpcf7cfRepeater.prototype.getParentRepeaters = function() { |
| 798 | const simplifiedDomArray = Object.values(wpcf7cf.get_simplified_dom_model(form.$form[0])); |
| 799 | form.repeaters.map(repeater => { |
| 800 | |
| 801 | }); |
| 802 | }; |
| 803 | |
| 804 | Wpcf7cfRepeater.prototype.removeSubs = function(subs_to_remove, index=null) { |
| 805 | const $ = jQuery; |
| 806 | const repeater = this; |
| 807 | const params = repeater.params; |
| 808 | const form = repeater.form; |
| 809 | const $repeater = params.$repeater; |
| 810 | |
| 811 | if ($repeater.num_subs - subs_to_remove < $repeater.min) { |
| 812 | subs_to_remove = $repeater.num_subs - $repeater.min; |
| 813 | } |
| 814 | |
| 815 | if (index===null) { |
| 816 | index = $repeater.num_subs-subs_to_remove; |
| 817 | } |
| 818 | $repeater.num_subs-= subs_to_remove; |
| 819 | |
| 820 | jQuery('> .wpcf7cf_repeater_sub',$repeater).finish(); // finish any currently running animations immediately. |
| 821 | |
| 822 | jQuery('> .wpcf7cf_repeater_sub',$repeater).slice(index,index+subs_to_remove).animate(wpcf7cf_hide_animation, {duration:params.wpcf7cf_settings.animation_intime, done:function() { |
| 823 | const $this = jQuery(this); |
| 824 | //remove the actual fields from the form |
| 825 | $this.remove(); |
| 826 | params.$repeater.trigger('wpcf7cf_repeater_removed'); |
| 827 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 828 | form.updateGroups(); |
| 829 | form.updateEventListeners(); |
| 830 | form.displayFields(); |
| 831 | |
| 832 | repeater.updateButtons(); |
| 833 | |
| 834 | if (index !== null) { |
| 835 | repeater.updateSuffixes(); |
| 836 | } |
| 837 | }}); |
| 838 | |
| 839 | return false; |
| 840 | }; |
| 841 | |
| 842 | function Wpcf7cfMultistep($multistep, form) { |
| 843 | const multistep = this; |
| 844 | multistep.$multistep = $multistep; |
| 845 | multistep.form = form; |
| 846 | multistep.$steps = $multistep.find('.wpcf7cf_step'); |
| 847 | multistep.$btn_next = $multistep.find('.wpcf7cf_next'); |
| 848 | multistep.$btn_prev = $multistep.find('.wpcf7cf_prev'); |
| 849 | multistep.$dots = $multistep.find('.wpcf7cf_steps-dots'); |
| 850 | multistep.currentStep = 0; |
| 851 | multistep.numSteps = multistep.$steps.length; |
| 852 | |
| 853 | |
| 854 | multistep.$dots.html(''); |
| 855 | for (let i = 1; i <= multistep.numSteps; i++) { |
| 856 | multistep.$dots.append(` |
| 857 | <div class="dot" data-step="${i}"> |
| 858 | <div class="step-index">${i}</div> |
| 859 | <div class="step-title">${multistep.$steps.eq(i-1).attr('data-title')}</div> |
| 860 | </div> |
| 861 | `); |
| 862 | } |
| 863 | |
| 864 | multistep.$btn_next.on('click.wpcf7cf_step', async function() { |
| 865 | |
| 866 | multistep.$btn_next.addClass('disabled').attr('disabled', true); |
| 867 | multistep.form.$form.addClass('submitting'); |
| 868 | const result = await multistep.validateStep(multistep.currentStep); |
| 869 | multistep.form.$form.removeClass('submitting'); |
| 870 | |
| 871 | if (result === 'success') { |
| 872 | multistep.moveToStep(multistep.currentStep+1); |
| 873 | } |
| 874 | |
| 875 | }); |
| 876 | |
| 877 | // If form is submitted (by pressing Enter for example), and if we are not on the last step, |
| 878 | // then trigger click event on the $btn_next button instead. |
| 879 | multistep.form.$form.on('submit.wpcf7cf_step', function(e) { |
| 880 | |
| 881 | if (multistep.currentStep !== multistep.numSteps) { |
| 882 | multistep.$btn_next.trigger('click.wpcf7cf_step'); |
| 883 | |
| 884 | e.stopImmediatePropagation(); |
| 885 | return false; |
| 886 | } |
| 887 | }); |
| 888 | |
| 889 | multistep.$btn_prev.on( 'click', function() { |
| 890 | multistep.moveToStep(multistep.currentStep-1); |
| 891 | }); |
| 892 | |
| 893 | multistep.moveToStep(1); |
| 894 | } |
| 895 | |
| 896 | Wpcf7cfMultistep.prototype.validateStep = function(step_index) { |
| 897 | |
| 898 | const multistep = this; |
| 899 | const $multistep = multistep.$multistep; |
| 900 | const $form = multistep.form.$form; |
| 901 | const form = multistep.form; |
| 902 | |
| 903 | $form.find('.wpcf7-response-output').addClass('wpcf7-display-none'); |
| 904 | |
| 905 | return new Promise(resolve => { |
| 906 | |
| 907 | const fd = new FormData(); |
| 908 | |
| 909 | // Make sure to add file fields to FormData |
| 910 | jQuery.each($form.find('[data-id="step-'+step_index+'"] input[type="file"]'), function(index, el) { |
| 911 | if (! el.files.length) return true; // = continue |
| 912 | const file = el.files[0]; |
| 913 | const fieldName = el.name; |
| 914 | fd.append(fieldName, file); |
| 915 | }); |
| 916 | |
| 917 | const formdata = $form.serializeArray(); |
| 918 | jQuery.each(formdata,function(key, input){ |
| 919 | fd.append(input.name, input.value); |
| 920 | }); |
| 921 | |
| 922 | jQuery.ajax({ |
| 923 | url: wpcf7cf_global_settings.ajaxurl + '?action=wpcf7cf_validate_step', |
| 924 | type: 'POST', |
| 925 | data: fd, |
| 926 | processData: false, |
| 927 | contentType: false, |
| 928 | dataType: 'json', |
| 929 | }).done(function(json) { |
| 930 | |
| 931 | $multistep.find('.wpcf7-form-control-wrap .wpcf7-not-valid-tip').remove(); |
| 932 | $multistep.find('.wpcf7-not-valid').removeClass('wpcf7-not-valid'); |
| 933 | $multistep.find('.wpcf7-response-output').remove(); |
| 934 | $multistep.find('.wpcf7-response-output.wpcf7-validation-errors').removeClass('wpcf7-validation-errors'); |
| 935 | |
| 936 | multistep.$btn_next.removeClass('disabled').attr('disabled', false); |
| 937 | |
| 938 | if (!json.success) { |
| 939 | let checkError = 0; |
| 940 | |
| 941 | jQuery.each(json.invalid_fields, function(index, el) { |
| 942 | if ($multistep.find('input[name="'+index+'"]').length || |
| 943 | $multistep.find('input[name="'+index+'[]"]').length || |
| 944 | $multistep.find('select[name="'+index+'"]').length || |
| 945 | $multistep.find('select[name="'+index+'[]"]').length || |
| 946 | $multistep.find('textarea[name="'+index+'"]').length || |
| 947 | $multistep.find('textarea[name="'+index+'[]"]').length |
| 948 | ) { |
| 949 | checkError = checkError + 1; |
| 950 | |
| 951 | const controlWrap = form.get(`.wpcf7-form-control-wrap[data-name="${index}"]`); |
| 952 | controlWrap.find('.wpcf7-form-control').addClass('wpcf7-not-valid'); |
| 953 | controlWrap.find('span.wpcf7-not-valid-tip').remove(); |
| 954 | controlWrap.append('<span role="alert" class="wpcf7-not-valid-tip">' + el.reason + '</span>'); |
| 955 | |
| 956 | } |
| 957 | }); |
| 958 | |
| 959 | resolve('failed'); |
| 960 | |
| 961 | $multistep.parent().find('.wpcf7-response-output').removeClass('wpcf7-display-none').html(json.message); |
| 962 | |
| 963 | wpcf7.setStatus( $form, 'invalid' ); |
| 964 | multistep.$steps.trigger('wpcf7cf_step_invalid'); |
| 965 | |
| 966 | // wpcf7.triggerEvent( data.into, 'invalid', detail ); |
| 967 | |
| 968 | } else if (json.success) { |
| 969 | |
| 970 | wpcf7.setStatus( $form, 'init' ); |
| 971 | |
| 972 | resolve('success'); |
| 973 | return false; |
| 974 | } |
| 975 | |
| 976 | }).fail(function() { |
| 977 | resolve('error'); |
| 978 | }).always(function() { |
| 979 | // do nothing |
| 980 | }); |
| 981 | }); |
| 982 | |
| 983 | }; |
| 984 | Wpcf7cfMultistep.prototype.moveToStep = function(step_index, scrollToTop = true) { |
| 985 | const multistep = this; |
| 986 | const previousStep = multistep.currentStep; |
| 987 | |
| 988 | multistep.currentStep = step_index > multistep.numSteps ? multistep.numSteps |
| 989 | : step_index < 1 ? 1 |
| 990 | : step_index; |
| 991 | |
| 992 | // ANIMATION DISABLED FOR NOW cause it's ugly |
| 993 | // multistep.$steps.animate(wpcf7cf_hide_step_animation, multistep.form.settings.animation_outtime); |
| 994 | // multistep.$steps.eq(multistep.currentStep-1).animate(wpcf7cf_show_step_animation, multistep.form.settings.animation_intime); |
| 995 | |
| 996 | multistep.$multistep.attr('data-current_step', multistep.currentStep); |
| 997 | multistep.$steps.hide(); |
| 998 | multistep.$steps |
| 999 | .eq(multistep.currentStep-1) |
| 1000 | .show() |
| 1001 | .trigger('wpcf7cf_change_step', [previousStep, multistep.currentStep]); |
| 1002 | |
| 1003 | if (scrollToTop) { |
| 1004 | const formEl = multistep.form.$form[0]; |
| 1005 | const topOffset = formEl.getBoundingClientRect().top; |
| 1006 | if (topOffset < 0 && previousStep > 0) { |
| 1007 | formEl.scrollIntoView({behavior: "smooth"}); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | multistep.form.updateSummaryFields(); |
| 1012 | |
| 1013 | window.wpcf7cf.updateMultistepState(multistep); |
| 1014 | }; |
| 1015 | |
| 1016 | Wpcf7cfMultistep.prototype.getFieldsInStep = function(step_index) { |
| 1017 | this.form.reloadSimpleDom(); |
| 1018 | let inStep = false; |
| 1019 | return Object.values(this.form.simpleDom).filter(function(item, i) { |
| 1020 | if(item.type == 'step') { |
| 1021 | inStep = item.val == step_index+''; |
| 1022 | } |
| 1023 | return inStep && item.type == 'input'; |
| 1024 | }).map(function(item) { |
| 1025 | return item.name; |
| 1026 | }); |
| 1027 | }; |
| 1028 | |
| 1029 | // END PRO ONLY |
| 1030 | |
| 1031 | /** |
| 1032 | * @global |
| 1033 | * @namespace wpcf7cf |
| 1034 | */ |
| 1035 | window.wpcf7cf = { |
| 1036 | |
| 1037 | hideGroup : function($group, animate) { |
| 1038 | |
| 1039 | }, |
| 1040 | |
| 1041 | showGroup : function($group, animate) { |
| 1042 | |
| 1043 | }, |
| 1044 | |
| 1045 | updateRepeaterSubHTML : function(html, oldSuffix, newSuffix, parentRepeaters) { |
| 1046 | const oldIndexes = oldSuffix.split('__'); |
| 1047 | oldIndexes.shift(); // remove first empty element |
| 1048 | const newIndexes = newSuffix.split('__'); |
| 1049 | newIndexes.shift(); // remove first empty element |
| 1050 | |
| 1051 | let returnHtml = html; |
| 1052 | |
| 1053 | if ( |
| 1054 | oldIndexes && newIndexes && |
| 1055 | oldIndexes.length === parentRepeaters.length && |
| 1056 | newIndexes.length === parentRepeaters.length |
| 1057 | ) { |
| 1058 | |
| 1059 | const parentRepeatersInfo = parentRepeaters.map((repeaterId, i) => { |
| 1060 | return {[repeaterId.split('__')[0]]: [oldIndexes[i], newIndexes[i]]}; |
| 1061 | }); |
| 1062 | |
| 1063 | const length = parentRepeatersInfo.length; |
| 1064 | |
| 1065 | let replacements = oldIndexes.map( (oldIndex, i) => { |
| 1066 | return [ |
| 1067 | '__'+oldIndexes.slice(0,length-i).join('__'), |
| 1068 | '__'+newIndexes.slice(0,length-i).join('__'), |
| 1069 | ]; |
| 1070 | }); |
| 1071 | |
| 1072 | |
| 1073 | for (let i=0; i<length ; i++) { |
| 1074 | const id = Object.keys(parentRepeatersInfo[i])[0]; |
| 1075 | const find = parentRepeatersInfo[i][id][0]; |
| 1076 | const repl = parentRepeatersInfo[i][id][1]; |
| 1077 | replacements.push([ |
| 1078 | `<span class="wpcf7cf-index wpcf7cf__${id}">${find}<\\/span>`, |
| 1079 | `<span class="wpcf7cf-index wpcf7cf__${id}">${repl}</span>` |
| 1080 | ]); |
| 1081 | } |
| 1082 | |
| 1083 | replacements.forEach( ([oldSuffix, newSuffix]) => { |
| 1084 | returnHtml = returnHtml.replace(new RegExp(oldSuffix,'g'), newSuffix); |
| 1085 | }); |
| 1086 | |
| 1087 | } |
| 1088 | |
| 1089 | return returnHtml ; |
| 1090 | }, |
| 1091 | |
| 1092 | // keep this for backwards compatibility |
| 1093 | initForm : function($forms) { |
| 1094 | $forms.each(function(){ |
| 1095 | const $form = jQuery(this); |
| 1096 | // only add form is its class is "wpcf7-form" and if the form was not previously added |
| 1097 | if ( |
| 1098 | $form.hasClass('wpcf7-form') && |
| 1099 | !wpcf7cf_forms.some((form)=>{ return form.$form.get(0) === $form.get(0); }) |
| 1100 | ) { |
| 1101 | wpcf7cf_forms.push(new Wpcf7cfForm($form)); |
| 1102 | } |
| 1103 | }); |
| 1104 | }, |
| 1105 | |
| 1106 | getWpcf7cfForm : function ($form) { |
| 1107 | const matched_forms = wpcf7cf_forms.filter((form)=>{ |
| 1108 | return form.$form.get(0) === $form.get(0); |
| 1109 | }); |
| 1110 | if (matched_forms.length) { |
| 1111 | return matched_forms[0]; |
| 1112 | } |
| 1113 | return false; |
| 1114 | }, |
| 1115 | |
| 1116 | get_nested_conditions : function(form) { |
| 1117 | const conditions = form.initial_conditions; |
| 1118 | //loop trough conditions. Then loop trough the dom, and each repeater we pass we should update all sub_values we encounter with __index |
| 1119 | form.reloadSimpleDom(); |
| 1120 | const groups = Object.values(form.simpleDom).filter(function(item, i) { |
| 1121 | return item.type==='group'; |
| 1122 | }); |
| 1123 | |
| 1124 | let sub_conditions = []; |
| 1125 | |
| 1126 | for(let i = 0; i < groups.length; i++) { |
| 1127 | const g = groups[i]; |
| 1128 | let relevant_conditions = conditions.filter(function(condition, i) { |
| 1129 | return condition.then_field === g.original_name; |
| 1130 | }); |
| 1131 | |
| 1132 | relevant_conditions = relevant_conditions.map(function(item,i) { |
| 1133 | return { |
| 1134 | then_field : g.name, |
| 1135 | and_rules : item.and_rules.map(function(and_rule, i) { |
| 1136 | return { |
| 1137 | if_field : and_rule.if_field+g.suffix, |
| 1138 | if_value : and_rule.if_value, |
| 1139 | operator : and_rule.operator |
| 1140 | }; |
| 1141 | }) |
| 1142 | } |
| 1143 | }); |
| 1144 | |
| 1145 | sub_conditions = sub_conditions.concat(relevant_conditions); |
| 1146 | } |
| 1147 | return sub_conditions; |
| 1148 | }, |
| 1149 | |
| 1150 | get_simplified_dom_model : function(currentNode, simplified_dom = {}, parentGroups = [], parentRepeaters = []) { |
| 1151 | |
| 1152 | const type = currentNode.classList && currentNode.classList.contains('wpcf7cf_repeater') ? 'repeater' : |
| 1153 | currentNode.dataset.class == 'wpcf7cf_group' ? 'group' : |
| 1154 | currentNode.className == 'wpcf7cf_step' ? 'step' : |
| 1155 | currentNode.hasAttribute('name') ? 'input' : false; |
| 1156 | |
| 1157 | let newParentRepeaters = [...parentRepeaters]; |
| 1158 | let newParentGroups = [...parentGroups]; |
| 1159 | |
| 1160 | if (type) { |
| 1161 | |
| 1162 | const name = type === 'input' ? currentNode.getAttribute('name') : currentNode.dataset.id; |
| 1163 | |
| 1164 | if (type === 'repeater') { |
| 1165 | newParentRepeaters.push(name); |
| 1166 | } |
| 1167 | if (type === 'group') { |
| 1168 | newParentGroups.push(name); |
| 1169 | } |
| 1170 | |
| 1171 | // skip _wpcf7 hidden fields |
| 1172 | if (name.substring(0,6) === '_wpcf7') return {}; |
| 1173 | |
| 1174 | const original_name = type === 'repeater' || type === 'group' ? currentNode.dataset.orig_data_id |
| 1175 | : type === 'input' ? (currentNode.getAttribute('data-orig_name') || name) |
| 1176 | : name; |
| 1177 | |
| 1178 | const nameWithoutBrackets = name.replace('[]',''); |
| 1179 | const originalNameWithoutBrackets = original_name.replace('[]',''); |
| 1180 | |
| 1181 | const val = type === 'step' ? [currentNode.dataset.id.substring(5)] : []; |
| 1182 | |
| 1183 | const suffix = nameWithoutBrackets.replace(originalNameWithoutBrackets, ''); |
| 1184 | |
| 1185 | if (!simplified_dom[name]) { |
| 1186 | // init entry |
| 1187 | simplified_dom[name] = {name, type, original_name, suffix, val, parentGroups, parentRepeaters} |
| 1188 | } |
| 1189 | |
| 1190 | if (type === 'input') { |
| 1191 | |
| 1192 | // skip unchecked checkboxes and radiobuttons |
| 1193 | if ( (currentNode.type === 'checkbox' || currentNode.type === 'radio') && !currentNode.checked ) return {}; |
| 1194 | |
| 1195 | // if multiselect, make sure to add all the values |
| 1196 | if ( currentNode.multiple && currentNode.options ) { |
| 1197 | simplified_dom[name].val = Object.values(currentNode.options).filter(o => o.selected).map(o => o.value) |
| 1198 | } else { |
| 1199 | simplified_dom[name].val.push(currentNode.value); |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | // can't use currentNode.children (because then field name cannot be "children") |
| 1205 | const getter = Object.getOwnPropertyDescriptor(Element.prototype, "children").get; |
| 1206 | const children = getter.call(currentNode); |
| 1207 | |
| 1208 | Array.from(children).forEach(childNode => { |
| 1209 | const dom = wpcf7cf.get_simplified_dom_model(childNode, simplified_dom, newParentGroups, newParentRepeaters); |
| 1210 | simplified_dom = {...dom, ...simplified_dom} ; |
| 1211 | }); |
| 1212 | |
| 1213 | return simplified_dom; |
| 1214 | }, |
| 1215 | |
| 1216 | updateMultistepState: function (multistep) { |
| 1217 | if (multistep == null) return; |
| 1218 | |
| 1219 | // update hidden input field |
| 1220 | |
| 1221 | const stepsData = { |
| 1222 | currentStep : multistep.currentStep, |
| 1223 | numSteps : multistep.numSteps, |
| 1224 | fieldsInCurrentStep : multistep.getFieldsInStep(multistep.currentStep) |
| 1225 | }; |
| 1226 | multistep.form.$input_steps.val(JSON.stringify(stepsData)); |
| 1227 | |
| 1228 | // update Buttons |
| 1229 | multistep.$btn_prev.removeClass('disabled').attr('disabled', false); |
| 1230 | multistep.$btn_next.removeClass('disabled').attr('disabled', false); |
| 1231 | if (multistep.currentStep == multistep.numSteps) { |
| 1232 | multistep.$btn_next.addClass('disabled').attr('disabled', true); |
| 1233 | } |
| 1234 | if (multistep.currentStep == 1) { |
| 1235 | multistep.$btn_prev.addClass('disabled').attr('disabled', true); |
| 1236 | } |
| 1237 | |
| 1238 | // replace next button with submit button on last step. |
| 1239 | // TODO: make this depend on a setting |
| 1240 | const $submit_button = multistep.form.$form.find('input[type="submit"]:last').eq(0); |
| 1241 | const $ajax_loader = multistep.form.$form.find('.wpcf7-spinner').eq(0); |
| 1242 | |
| 1243 | $submit_button.detach().prependTo(multistep.$btn_next.parent()); |
| 1244 | $ajax_loader.detach().prependTo(multistep.$btn_next.parent()); |
| 1245 | |
| 1246 | if (multistep.currentStep == multistep.numSteps) { |
| 1247 | multistep.$btn_next.hide(); |
| 1248 | $submit_button.show(); |
| 1249 | } else { |
| 1250 | $submit_button.hide(); |
| 1251 | multistep.$btn_next.show(); |
| 1252 | } |
| 1253 | |
| 1254 | // update dots |
| 1255 | const $dots = multistep.$dots.find('.dot'); |
| 1256 | $dots.removeClass('active').removeClass('completed'); |
| 1257 | for(let step = 1; step <= multistep.numSteps; step++) { |
| 1258 | if (step < multistep.currentStep) { |
| 1259 | $dots.eq(step-1).addClass('completed'); |
| 1260 | } else if (step == multistep.currentStep) { |
| 1261 | $dots.eq(step-1).addClass('active'); |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | }, |
| 1266 | |
| 1267 | should_group_be_shown : function(condition, form) { |
| 1268 | |
| 1269 | let show_group = true; |
| 1270 | let atLeastOneFieldFound = false; |
| 1271 | |
| 1272 | for (let and_rule_i = 0; and_rule_i < condition.and_rules.length; and_rule_i++) { |
| 1273 | |
| 1274 | let condition_ok = false; |
| 1275 | |
| 1276 | const condition_and_rule = condition.and_rules[and_rule_i]; |
| 1277 | |
| 1278 | const inputField = form.getFieldByName(condition_and_rule.if_field); |
| 1279 | |
| 1280 | if (!inputField) continue; // field not found |
| 1281 | |
| 1282 | atLeastOneFieldFound = true; |
| 1283 | |
| 1284 | const if_val = condition_and_rule.if_value; |
| 1285 | let operator = condition_and_rule.operator; |
| 1286 | |
| 1287 | //backwards compat |
| 1288 | operator = operator === '≤' ? 'less than or equals' : operator; |
| 1289 | operator = operator === '≥' ? 'greater than or equals' : operator; |
| 1290 | operator = operator === '>' ? 'greater than' : operator; |
| 1291 | operator = operator === '<' ? 'less than' : operator; |
| 1292 | |
| 1293 | const $field = operator === 'function' && jQuery(`[name="${inputField.name}"]`).eq(0); |
| 1294 | |
| 1295 | condition_ok = this.isConditionTrue(inputField.val,operator,if_val, $field); |
| 1296 | |
| 1297 | show_group = show_group && condition_ok; |
| 1298 | } |
| 1299 | |
| 1300 | return show_group && atLeastOneFieldFound; |
| 1301 | |
| 1302 | }, |
| 1303 | |
| 1304 | isConditionTrue(values, operator, testValue='', $field=jQuery()) { |
| 1305 | |
| 1306 | if (!Array.isArray(values)) { |
| 1307 | values = [values]; |
| 1308 | } |
| 1309 | |
| 1310 | let condition_ok = false; // start by assuming that the condition is not met |
| 1311 | |
| 1312 | // Considered EMPTY: [] [''] [null] ['',null] [,,''] |
| 1313 | // Considered NOT EMPTY: [0] ['ab','c'] ['',0,null] |
| 1314 | const valuesAreEmpty = values.length === 0 || values.every((v) => !v&&v!==0); // 0 is not considered empty |
| 1315 | |
| 1316 | // special cases: [] equals '' => TRUE; [] not equals '' => FALSE |
| 1317 | if (operator === 'equals' && testValue === '' && valuesAreEmpty) { |
| 1318 | return true; |
| 1319 | } |
| 1320 | if (operator === 'not equals' && testValue === '' && valuesAreEmpty) { |
| 1321 | return false; |
| 1322 | } |
| 1323 | |
| 1324 | if (valuesAreEmpty) { |
| 1325 | if (operator === 'is empty') { |
| 1326 | condition_ok = true; |
| 1327 | } |
| 1328 | } else { |
| 1329 | if (operator === 'not empty') { |
| 1330 | condition_ok = true; |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | const testValueNumber = isFinite(parseFloat(testValue)) ? parseFloat(testValue) : NaN; |
| 1335 | |
| 1336 | |
| 1337 | if (operator === 'not equals' || operator === 'not equals (regex)') { |
| 1338 | // start by assuming that the condition is met |
| 1339 | condition_ok = true; |
| 1340 | } |
| 1341 | |
| 1342 | if ( |
| 1343 | operator === 'function' |
| 1344 | && typeof window[testValue] == 'function' |
| 1345 | && window[testValue]($field) // here we call the actual user defined function |
| 1346 | ) { |
| 1347 | condition_ok = true; |
| 1348 | } |
| 1349 | |
| 1350 | let regex_patt = /.*/i; // fallback regex pattern |
| 1351 | let isValidRegex = true; |
| 1352 | if (operator === 'equals (regex)' || operator === 'not equals (regex)') { |
| 1353 | try { |
| 1354 | regex_patt = new RegExp(testValue, 'i'); |
| 1355 | } catch(e) { |
| 1356 | isValidRegex = false; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | |
| 1361 | for(let i = 0; i < values.length; i++) { |
| 1362 | |
| 1363 | const value = values[i]; |
| 1364 | |
| 1365 | const valueNumber = isFinite(parseFloat(value)) ? parseFloat(value) : NaN; |
| 1366 | const valsAreNumbers = !isNaN(valueNumber) && !isNaN(testValueNumber); |
| 1367 | |
| 1368 | if ( |
| 1369 | |
| 1370 | operator === 'equals' && value === testValue || |
| 1371 | operator === 'equals (regex)' && regex_patt.test(value) || |
| 1372 | operator === 'greater than' && valsAreNumbers && valueNumber > testValueNumber || |
| 1373 | operator === 'less than' && valsAreNumbers && valueNumber < testValueNumber || |
| 1374 | operator === 'greater than or equals' && valsAreNumbers && valueNumber >= testValueNumber || |
| 1375 | operator === 'less than or equals' && valsAreNumbers && valueNumber <= testValueNumber |
| 1376 | |
| 1377 | ) { |
| 1378 | |
| 1379 | condition_ok = true; |
| 1380 | break; |
| 1381 | |
| 1382 | } else if ( |
| 1383 | |
| 1384 | operator === 'not equals' && value === testValue || |
| 1385 | operator === 'not equals (regex)' && regex_patt.test(value) |
| 1386 | |
| 1387 | ) { |
| 1388 | |
| 1389 | condition_ok = false; |
| 1390 | break; |
| 1391 | |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | return condition_ok; |
| 1396 | |
| 1397 | }, |
| 1398 | |
| 1399 | getFormObj($form) { |
| 1400 | if (typeof $form === 'string') { |
| 1401 | $form = jQuery($form).eq(0); |
| 1402 | } |
| 1403 | return wpcf7cf.getWpcf7cfForm($form); |
| 1404 | }, |
| 1405 | |
| 1406 | getRepeaterObj($form, repeaterDataId) { |
| 1407 | const form = wpcf7cf.getFormObj($form); |
| 1408 | const repeater = form.repeaters.find( repeater => repeater.params.$repeater.attr('data-id') === repeaterDataId ); |
| 1409 | |
| 1410 | return repeater; |
| 1411 | |
| 1412 | }, |
| 1413 | |
| 1414 | getMultiStepObj($form){ |
| 1415 | const form = wpcf7cf.getFormObj($form); |
| 1416 | return form.multistep; |
| 1417 | }, |
| 1418 | |
| 1419 | /** |
| 1420 | * Append a new sub-entry to the repeater with the name `repeaterDataId` inside the form `$form` |
| 1421 | * @memberof wpcf7cf |
| 1422 | * @function wpcf7cf.repeaterAddSub |
| 1423 | * @link |
| 1424 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1425 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. Normally this is simply the name of the repeater. However, in case of a nested repeater you need to append the name with the correct suffix. For example `my-nested-repeater__1__3`. Hint (check the `data-id` attribute in the HTML code to find the correct suffix) |
| 1426 | */ |
| 1427 | repeaterAddSub($form,repeaterDataId) { |
| 1428 | const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1429 | repeater.updateSubs(repeater.params.$repeater.num_subs+1); |
| 1430 | }, |
| 1431 | |
| 1432 | /** |
| 1433 | * Insert a new sub-entry at the given `index` of the repeater with the name `repeaterDataId` inside the form `$form` |
| 1434 | * @memberof wpcf7cf |
| 1435 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1436 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1437 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1438 | */ |
| 1439 | repeaterAddSubAtIndex($form,repeaterDataId,index) { |
| 1440 | const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1441 | repeater.addSubs(1, index); |
| 1442 | }, |
| 1443 | |
| 1444 | /** |
| 1445 | * Remove the sub-entry at the given `index` of the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form` |
| 1446 | * @memberof wpcf7cf |
| 1447 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1448 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1449 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1450 | */ |
| 1451 | repeaterRemoveSubAtIndex($form,repeaterDataId,index) { |
| 1452 | const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1453 | repeater.removeSubs(1, index); |
| 1454 | }, |
| 1455 | |
| 1456 | /** |
| 1457 | * Remove the last sub-entry from the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form` |
| 1458 | * @memberof wpcf7cf |
| 1459 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1460 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1461 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1462 | */ |
| 1463 | repeaterRemoveSub($form,repeaterDataId) { |
| 1464 | const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1465 | repeater.updateSubs(repeater.params.$repeater.num_subs-1); |
| 1466 | }, |
| 1467 | |
| 1468 | /** |
| 1469 | * Set the number of subs for the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form`. |
| 1470 | * Subs are either appended to or removed from the end of the repeater. |
| 1471 | * @memberof wpcf7cf |
| 1472 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1473 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1474 | * @param {Number} numberOfSubs - position where to insert the new sub-entry within the repeater |
| 1475 | */ |
| 1476 | repeaterSetNumberOfSubs($form, repeaterDataId, numberOfSubs) { |
| 1477 | const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1478 | repeater.updateSubs(numberOfSubs); |
| 1479 | }, |
| 1480 | |
| 1481 | /** |
| 1482 | * Move to step number `step`, ignoring any validation. |
| 1483 | * @memberof wpcf7cf |
| 1484 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1485 | * @param {*} step |
| 1486 | */ |
| 1487 | multistepMoveToStep($form, step) { |
| 1488 | const multistep = wpcf7cf.getMultiStepObj($form); |
| 1489 | multistep.moveToStep(step); |
| 1490 | }, |
| 1491 | |
| 1492 | /** |
| 1493 | * Validate the current step, and move to step number `step` if validation passes. |
| 1494 | * @memberof wpcf7cf |
| 1495 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1496 | * @param {Number} step |
| 1497 | */ |
| 1498 | async multistepMoveToStepWithValidation($form, step) { |
| 1499 | const multistep = wpcf7cf.getMultiStepObj($form); |
| 1500 | |
| 1501 | const result = await multistep.validateStep(multistep.currentStep); |
| 1502 | if (result === 'success') { |
| 1503 | multistep.moveToStep(step); |
| 1504 | } |
| 1505 | }, |
| 1506 | |
| 1507 | |
| 1508 | }; |
| 1509 | |
| 1510 | jQuery('.wpcf7-form').each(function(){ |
| 1511 | wpcf7cf_forms.push(new Wpcf7cfForm(jQuery(this))); |
| 1512 | }); |
| 1513 | |
| 1514 | // Call displayFields again on all forms |
| 1515 | // Necessary in case some theme or plugin changed a form value by the time the entire page is fully loaded. |
| 1516 | jQuery('document').ready( function() { |
| 1517 | wpcf7cf_forms.forEach(function(f){ |
| 1518 | f.displayFields(); |
| 1519 | }); |
| 1520 | }); |
| 1521 | |
| 1522 | // fix for exclusive checkboxes in IE (this will call the change-event again after all other checkboxes are unchecked, triggering the display_fields() function) |
| 1523 | const old_wpcf7ExclusiveCheckbox = jQuery.fn.wpcf7ExclusiveCheckbox; |
| 1524 | jQuery.fn.wpcf7ExclusiveCheckbox = function() { |
| 1525 | return this.find('input:checkbox').on('click', function() { |
| 1526 | const name = jQuery(this).attr('name'); |
| 1527 | jQuery(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false).eq(0).change(); |
| 1528 | }); |
| 1529 | };</code></pre> |
| 1530 | </article> |
| 1531 | </section> |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | </div> |
| 1537 | |
| 1538 | <nav> |
| 1539 | <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="wpcf7cf.html">wpcf7cf</a></li></ul> |
| 1540 | </nav> |
| 1541 | |
| 1542 | <br class="clear"> |
| 1543 | |
| 1544 | <footer> |
| 1545 | Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 13 2023 02:00:25 GMT+0100 (GMT+01:00) |
| 1546 | </footer> |
| 1547 | |
| 1548 | <script> prettyPrint(); </script> |
| 1549 | <script src="scripts/linenumber.js"> </script> |
| 1550 | </body> |
| 1551 | </html> |
| 1552 |