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