PluginProbe ʕ •ᴥ•ʔ
Conditional Fields for Contact Form 7 / 2.5.13
Conditional Fields for Contact Form 7 v2.5.13
2.7.10 2.7.9 2.7.8 2.7.7 2.7.6 2.7.5 2.7.4 2.7.3 2.7.2 0.2.4 0.2.5 0.2.6 0.2.7 0.2.8 0.2.9 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6.1 1.6.2 1.6.3 1.6.5 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.8.7 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2 2.2.1 2.2.10 2.2.11 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.10 2.3.11 2.3.12 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.7 2.7.1 trunk 0.1 0.1.1 0.1.2 0.1.3 0.1.4 0.1.5 0.1.6 0.1.7 0.2 0.2.1 0.2.2 0.2.3
cf7-conditional-fields / jsdoc-out / scripts.js.html
cf7-conditional-fields / jsdoc-out Last commit date
fonts 5 years ago scripts 5 years ago styles 5 years ago global.html 5 years ago index.html 1 year ago module-wpcf7cf.html 5 years ago scripts.js.html 1 year ago scripts_es6.js.html 4 years ago wpcf7cf.html 1 year ago wpcf7cfApi.html 5 years ago
scripts.js.html
970 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 &amp;&amp; !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 &amp;&amp; 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 ( &lt; 1.4 )
182 for (let i=0; i &lt; 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
229
230 }
231
232 /**
233 * reset initial number of subs for each repeater.
234 * (does not clear values)
235 */
236 Wpcf7cfForm.prototype.resetRepeaters = function() {
237 const form = this;
238 form.repeaters.forEach(repeater => {
239 repeater.updateSubs( repeater.params.$repeater.initial_subs );
240 });
241 }
242
243 Wpcf7cfForm.prototype.displayFields = function() {
244
245 const form = this;
246
247 const wpcf7cf_conditions = this.conditions;
248 const wpcf7cf_settings = this.settings;
249
250 //for compatibility with contact-form-7-signature-addon
251 if (cf7signature_resized === 0 &amp;&amp; typeof signatures !== 'undefined' &amp;&amp; signatures.constructor === Array &amp;&amp; signatures.length > 0 ) {
252 for (let i = 0; i &lt; signatures.length; i++) {
253 if (signatures[i].canvas.width === 0) {
254
255 const $sig_canvas = jQuery(".wpcf7-form-control-signature-body>canvas");
256 const $sig_wrap = jQuery(".wpcf7-form-control-signature-wrap");
257 $sig_canvas.eq(i).attr('width', $sig_wrap.width());
258 $sig_canvas.eq(i).attr('height', $sig_wrap.height());
259
260 cf7signature_resized = 1;
261 }
262 }
263 }
264
265 form.$groups.addClass('wpcf7cf-hidden');
266
267 for (let i=0; i &lt; wpcf7cf_conditions.length; i++) {
268
269 const condition = wpcf7cf_conditions[i];
270
271 const show_group = window.wpcf7cf.should_group_be_shown(condition, form);
272
273 if (show_group) {
274 form.get('[data-id="'+condition.then_field+'"]').removeClass('wpcf7cf-hidden');
275 }
276 }
277
278
279 const animation_intime = wpcf7cf_settings.animation_intime;
280 const animation_outtime = wpcf7cf_settings.animation_outtime;
281
282 form.$groups.each(function (index) {
283 const $group = jQuery(this);
284 if ($group.is(':animated')) {
285 $group.finish(); // stop any current animations on the group
286 }
287 if ($group.css('display') === 'none' &amp;&amp; !$group.hasClass('wpcf7cf-hidden')) {
288 if ($group.prop('tagName') === 'SPAN') {
289 $group.show().trigger('wpcf7cf_show_group'); // show instantly
290 } else {
291 $group.animate(wpcf7cf_show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show with animation
292 }
293
294 if($group.attr('data-disable_on_hide') !== undefined) {
295 $group.find(':input').prop('disabled', false).trigger('changedisabledprop.wpcf7cf');
296 $group.find('.wpcf7-form-control-wrap').removeClass('wpcf7cf-disabled');
297 }
298
299 } else if ($group.css('display') !== 'none' &amp;&amp; $group.hasClass('wpcf7cf-hidden')) {
300
301 if ($group.attr('data-clear_on_hide') !== undefined) {
302 const $inputs = jQuery(':input', $group).not(':button, :submit, :reset, :hidden');
303
304 $inputs.each(function(){
305 const $this = jQuery(this);
306 $this.val(this.defaultValue);
307 $this.prop('checked', this.defaultChecked);
308 });
309
310 jQuery('option', $group).each(function() {
311 this.selected = this.defaultSelected;
312 });
313
314 jQuery('select', $group).each(function() {
315 const $select = jQuery(this);
316 if ($select.val() === null) {
317 $select.val(jQuery("option:first",$select).val());
318 }
319 });
320
321 $inputs.each(function(){this.dispatchEvent(new Event("change",{"bubbles":true}))});
322 }
323
324 if ($group.prop('tagName') === 'SPAN') {
325 $group.hide().trigger('wpcf7cf_hide_group');
326 } else {
327 $group.animate(wpcf7cf_hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide
328 }
329 }
330 });
331
332 form.updateHiddenFields();
333 form.updateSummaryFields();
334 };
335
336 Wpcf7cfForm.prototype.updateSummaryFields = function() {
337 const form = this;
338 const $summary = form.get('.wpcf7cf-summary');
339
340 if ($summary.length == 0 || !$summary.is(':visible')) {
341 return;
342 }
343
344 const fd = new FormData();
345
346 const formdata = form.$form.serializeArray();
347 jQuery.each(formdata,function(key, input){
348 fd.append(input.name, input.value);
349 });
350
351 // Make sure to add file fields to FormData
352 jQuery.each(form.$form.find('input[type="file"]'), function(index, el) {
353 if (! el.files.length) return true; // continue
354 const fieldName = el.name;
355 fd.append(fieldName, new Blob() , Array.from(el.files).map(file => file.name).join(', '));
356 });
357
358 // add file fields to form-data
359
360 jQuery.ajax({
361 url: wpcf7cf_global_settings.ajaxurl + '?action=wpcf7cf_get_summary',
362 type: 'POST',
363 data: fd,
364 processData: false,
365 contentType: false,
366 dataType: 'json',
367 success: function(json) {
368 $summary.html(json.summaryHtml);
369 }
370 });
371 };
372
373 Wpcf7cfForm.prototype.updateHiddenFields = function() {
374
375 const form = this;
376
377 const hidden_fields = [];
378 const hidden_groups = [];
379 const visible_groups = [];
380
381 form.$groups.each(function () {
382 const $group = jQuery(this);
383 if ($group.hasClass('wpcf7cf-hidden')) {
384 hidden_groups.push($group.attr('data-id'));
385 if($group.attr('data-disable_on_hide') !== undefined) {
386 // fields inside hidden disable_on_hide group
387 $group.find('input,select,textarea').each(function(){
388 const $this = jQuery(this);
389 if (!$this.prop('disabled')) {
390 $this.prop('disabled', true).trigger('changedisabledprop.wpcf7cf');
391 }
392
393 // if there's no other field with the same name visible in the form
394 // then push this field to hidden_fields
395 if (form.$form.find(`[data-class="wpcf7cf_group"]:not(.wpcf7cf-hidden) [name='${$this.attr('name')}']`).length === 0) {
396 hidden_fields.push($this.attr('name'));
397 }
398 })
399 $group.find('.wpcf7-form-control-wrap').addClass('wpcf7cf-disabled');
400 } else {
401 // fields inside regular hidden group are all pushed to hidden_fields
402 $group.find('input,select,textarea').each(function () {
403 hidden_fields.push(jQuery(this).attr('name'));
404 });
405 }
406 } else {
407 visible_groups.push($group.attr('data-id'));
408 }
409 });
410
411 form.hidden_fields = hidden_fields;
412 form.hidden_groups = hidden_groups;
413 form.visible_groups = visible_groups;
414
415 form.$input_hidden_group_fields.val(JSON.stringify(hidden_fields));
416 form.$input_hidden_groups.val(JSON.stringify(hidden_groups));
417 form.$input_visible_groups.val(JSON.stringify(visible_groups));
418
419 return true;
420 };
421 Wpcf7cfForm.prototype.updateGroups = function() {
422 const form = this;
423 form.$groups = form.$form.find('[data-class="wpcf7cf_group"]');
424 form.$groups.height('auto');
425 form.conditions = window.wpcf7cf.get_nested_conditions(form);
426
427 };
428 Wpcf7cfForm.prototype.updateEventListeners = function() {
429
430 const form = this;
431
432 // monitor input changes, and call displayFields() if something has changed
433 form.get('input, select, textarea, button').not('.wpcf7cf_add, .wpcf7cf_remove').off(wpcf7cf_change_events).on(wpcf7cf_change_events,form, function(e) {
434 const form = e.data;
435 clearTimeout(wpcf7cf_timeout);
436 wpcf7cf_timeout = setTimeout(function() {
437 window.wpcf7cf.updateMultistepState(form.multistep);
438 form.updateSimpleDom();
439 form.displayFields();
440 }, wpcf7cf_change_time_ms);
441 });
442
443
444 };
445
446
447
448 /**
449 * @global
450 * @namespace wpcf7cf
451 */
452 window.wpcf7cf = {
453
454 hideGroup : function($group, animate) {
455
456 },
457
458 showGroup : function($group, animate) {
459
460 },
461
462 updateRepeaterSubHTML : function(html, oldSuffix, newSuffix, parentRepeaters) {
463 const oldIndexes = oldSuffix.split('__');
464 oldIndexes.shift(); // remove first empty element
465 const newIndexes = newSuffix.split('__');
466 newIndexes.shift(); // remove first empty element
467
468 let returnHtml = html;
469
470 if (
471 oldIndexes &amp;&amp; newIndexes &amp;&amp;
472 oldIndexes.length === parentRepeaters.length &amp;&amp;
473 newIndexes.length === parentRepeaters.length
474 ) {
475
476 const parentRepeatersInfo = parentRepeaters.map((repeaterId, i) => {
477 return {[repeaterId.split('__')[0]]: [oldIndexes[i], newIndexes[i]]};
478 });
479
480 const length = parentRepeatersInfo.length;
481
482 let replacements = oldIndexes.map( (oldIndex, i) => {
483 return [
484 '__'+oldIndexes.slice(0,length-i).join('__'),
485 '__'+newIndexes.slice(0,length-i).join('__'),
486 ];
487 });
488
489
490 for (let i=0; i&lt;length ; i++) {
491 const id = Object.keys(parentRepeatersInfo[i])[0];
492 const find = parentRepeatersInfo[i][id][0];
493 const repl = parentRepeatersInfo[i][id][1];
494 replacements.push([
495 `&lt;span class="wpcf7cf-index wpcf7cf__${id}">${find}&lt;\\/span>`,
496 `&lt;span class="wpcf7cf-index wpcf7cf__${id}">${repl}&lt;/span>`
497 ]);
498 }
499
500 replacements.forEach( ([oldSuffix, newSuffix]) => {
501 returnHtml = returnHtml.replace(new RegExp(oldSuffix,'g'), newSuffix);
502 });
503
504 }
505
506 return returnHtml ;
507 },
508
509 // keep this for backwards compatibility
510 initForm : function($forms) {
511 $forms.each(function(){
512 const $form = jQuery(this);
513 // only add form is its class is "wpcf7-form" and if the form was not previously added
514 if (
515 $form.hasClass('wpcf7-form') &amp;&amp;
516 !wpcf7cf_forms.some((form)=>{ return form.$form.get(0) === $form.get(0); })
517 ) {
518 wpcf7cf_forms.push(new Wpcf7cfForm($form));
519 }
520 });
521 },
522
523 getWpcf7cfForm : function ($form) {
524 const matched_forms = wpcf7cf_forms.filter((form)=>{
525 return form.$form.get(0) === $form.get(0);
526 });
527 if (matched_forms.length) {
528 return matched_forms[0];
529 }
530 return false;
531 },
532
533 get_nested_conditions : function(form) {
534 const conditions = form.initial_conditions;
535 //loop trough conditions. Then loop trough the dom, and each repeater we pass we should update all sub_values we encounter with __index
536 form.reloadSimpleDom();
537 const groups = Object.values(form.simpleDom).filter(function(item, i) {
538 return item.type==='group';
539 });
540
541 let sub_conditions = [];
542
543 for(let i = 0; i &lt; groups.length; i++) {
544 const g = groups[i];
545 let relevant_conditions = conditions.filter(function(condition, i) {
546 return condition.then_field === g.original_name;
547 });
548
549 relevant_conditions = relevant_conditions.map(function(item,i) {
550 return {
551 then_field : g.name,
552 and_rules : item.and_rules.map(function(and_rule, i) {
553 return {
554 if_field : and_rule.if_field+g.suffix,
555 if_value : and_rule.if_value,
556 operator : and_rule.operator
557 };
558 })
559 }
560 });
561
562 sub_conditions = sub_conditions.concat(relevant_conditions);
563 }
564 return sub_conditions;
565 },
566
567 get_simplified_dom_model : function(currentNode, simplified_dom = {}, parentGroups = [], parentRepeaters = []) {
568
569 const type = currentNode.classList &amp;&amp; currentNode.classList.contains('wpcf7cf_repeater') ? 'repeater' :
570 currentNode.dataset.class == 'wpcf7cf_group' ? 'group' :
571 currentNode.className == 'wpcf7cf_step' ? 'step' :
572 currentNode.hasAttribute('name') ? 'input' : false;
573
574 let newParentRepeaters = [...parentRepeaters];
575 let newParentGroups = [...parentGroups];
576
577 if (type) {
578
579 const name = type === 'input' ? currentNode.getAttribute('name') : currentNode.dataset.id;
580
581 if (type === 'repeater') {
582 newParentRepeaters.push(name);
583 }
584 if (type === 'group') {
585 newParentGroups.push(name);
586 }
587
588 // skip _wpcf7 hidden fields
589 if (name.substring(0,6) === '_wpcf7') return {};
590
591 const original_name = type === 'repeater' || type === 'group' ? currentNode.dataset.orig_data_id
592 : type === 'input' ? (currentNode.getAttribute('data-orig_name') || name)
593 : name;
594
595 const nameWithoutBrackets = name.replace('[]','');
596 const originalNameWithoutBrackets = original_name.replace('[]','');
597
598 const val = type === 'step' ? [currentNode.dataset.id.substring(5)] : [];
599
600 const suffix = nameWithoutBrackets.replace(originalNameWithoutBrackets, '');
601
602 if (!simplified_dom[name]) {
603 // init entry
604 simplified_dom[name] = {name, type, original_name, suffix, val, parentGroups, parentRepeaters}
605 }
606
607 if (type === 'input') {
608
609 // skip unchecked checkboxes and radiobuttons
610 if ( (currentNode.type === 'checkbox' || currentNode.type === 'radio') &amp;&amp; !currentNode.checked ) return {};
611
612 // if multiselect, make sure to add all the values
613 if ( currentNode.multiple &amp;&amp; currentNode.options ) {
614 simplified_dom[name].val = Object.values(currentNode.options).filter(o => o.selected).map(o => o.value)
615 } else {
616 simplified_dom[name].val.push(currentNode.value);
617 }
618 }
619 }
620
621 // can't use currentNode.children (because then field name cannot be "children")
622 const getter = Object.getOwnPropertyDescriptor(Element.prototype, "children").get;
623 const children = getter.call(currentNode);
624
625 Array.from(children).forEach(childNode => {
626 const dom = wpcf7cf.get_simplified_dom_model(childNode, simplified_dom, newParentGroups, newParentRepeaters);
627 simplified_dom = {...dom, ...simplified_dom} ;
628 });
629
630 return simplified_dom;
631 },
632
633 updateMultistepState: function (multistep) {
634 if (multistep == null) return;
635 if (multistep.form.$form.hasClass('submitting')) return;
636
637 // update hidden input field
638
639 const stepsData = {
640 currentStep : multistep.currentStep,
641 numSteps : multistep.numSteps,
642 fieldsInCurrentStep : multistep.getFieldsInStep(multistep.currentStep)
643 };
644 multistep.form.$input_steps.val(JSON.stringify(stepsData));
645
646 // update Buttons
647 multistep.$btn_prev.removeClass('disabled').attr('disabled', false);
648 multistep.$btn_next.removeClass('disabled').attr('disabled', false);
649 if (multistep.currentStep == multistep.numSteps) {
650 multistep.$btn_next.addClass('disabled').attr('disabled', true);
651 }
652 if (multistep.currentStep == 1) {
653 multistep.$btn_prev.addClass('disabled').attr('disabled', true);
654 }
655
656 // replace next button with submit button on last step.
657 // TODO: make this depend on a setting
658 const $submit_button = multistep.form.$form.find('input[type="submit"]:last').eq(0);
659 const $ajax_loader = multistep.form.$form.find('.wpcf7-spinner').eq(0);
660
661 $submit_button.detach().prependTo(multistep.$btn_next.parent());
662 $ajax_loader.detach().prependTo(multistep.$btn_next.parent());
663
664 if (multistep.currentStep == multistep.numSteps) {
665 multistep.$btn_next.hide();
666 $submit_button.show();
667 } else {
668 $submit_button.hide();
669 multistep.$btn_next.show();
670 }
671
672 // update dots
673 const $dots = multistep.$dots.find('.dot');
674 $dots.removeClass('active').removeClass('completed');
675 for(let step = 1; step &lt;= multistep.numSteps; step++) {
676 if (step &lt; multistep.currentStep) {
677 $dots.eq(step-1).addClass('completed');
678 } else if (step == multistep.currentStep) {
679 $dots.eq(step-1).addClass('active');
680 }
681 }
682
683 },
684
685 should_group_be_shown : function(condition, form) {
686
687 let show_group = true;
688 let atLeastOneFieldFound = false;
689
690 for (let and_rule_i = 0; and_rule_i &lt; condition.and_rules.length; and_rule_i++) {
691
692 let condition_ok = false;
693
694 const condition_and_rule = condition.and_rules[and_rule_i];
695
696 const inputField = form.getFieldByName(condition_and_rule.if_field);
697
698 if (!inputField) continue; // field not found
699
700 atLeastOneFieldFound = true;
701
702 const if_val = condition_and_rule.if_value;
703 let operator = condition_and_rule.operator;
704
705 //backwards compat
706 operator = operator === '≤' ? 'less than or equals' : operator;
707 operator = operator === '≥' ? 'greater than or equals' : operator;
708 operator = operator === '>' ? 'greater than' : operator;
709 operator = operator === '&lt;' ? 'less than' : operator;
710
711 const $field = operator === 'function' &amp;&amp; jQuery(`[name="${inputField.name}"]`).eq(0);
712
713 condition_ok = this.isConditionTrue(inputField.val,operator,if_val, $field);
714
715 show_group = show_group &amp;&amp; condition_ok;
716 }
717
718 return show_group &amp;&amp; atLeastOneFieldFound;
719
720 },
721
722 isConditionTrue(values, operator, testValue='', $field=jQuery()) {
723
724 if (!Array.isArray(values)) {
725 values = [values];
726 }
727
728 let condition_ok = false; // start by assuming that the condition is not met
729
730 // Considered EMPTY: [] [''] [null] ['',null] [,,'']
731 // Considered NOT EMPTY: [0] ['ab','c'] ['',0,null]
732 const valuesAreEmpty = values.length === 0 || values.every((v) => !v&amp;&amp;v!==0); // 0 is not considered empty
733
734 // special cases: [] equals '' => TRUE; [] not equals '' => FALSE
735 if (operator === 'equals' &amp;&amp; testValue === '' &amp;&amp; valuesAreEmpty) {
736 return true;
737 }
738 if (operator === 'not equals' &amp;&amp; testValue === '' &amp;&amp; valuesAreEmpty) {
739 return false;
740 }
741
742 if (valuesAreEmpty) {
743 if (operator === 'is empty') {
744 condition_ok = true;
745 }
746 } else {
747 if (operator === 'not empty') {
748 condition_ok = true;
749 }
750 }
751
752 const testValueNumber = isFinite(parseFloat(testValue)) ? parseFloat(testValue) : NaN;
753
754
755 if (operator === 'not equals' || operator === 'not equals (regex)') {
756 // start by assuming that the condition is met
757 condition_ok = true;
758 }
759
760 if (
761 operator === 'function'
762 &amp;&amp; typeof window[testValue] == 'function'
763 &amp;&amp; window[testValue]($field) // here we call the actual user defined function
764 ) {
765 condition_ok = true;
766 }
767
768 let regex_patt = /.*/i; // fallback regex pattern
769 let isValidRegex = true;
770 if (operator === 'equals (regex)' || operator === 'not equals (regex)') {
771 try {
772 regex_patt = new RegExp(testValue, 'i');
773 } catch(e) {
774 isValidRegex = false;
775 }
776 }
777
778
779 for(let i = 0; i &lt; values.length; i++) {
780
781 const value = values[i];
782
783 const valueNumber = isFinite(parseFloat(value)) ? parseFloat(value) : NaN;
784 const valsAreNumbers = !isNaN(valueNumber) &amp;&amp; !isNaN(testValueNumber);
785
786 if (
787
788 operator === 'equals' &amp;&amp; value === testValue ||
789 operator === 'equals (regex)' &amp;&amp; regex_patt.test(value) ||
790 operator === 'greater than' &amp;&amp; valsAreNumbers &amp;&amp; valueNumber > testValueNumber ||
791 operator === 'less than' &amp;&amp; valsAreNumbers &amp;&amp; valueNumber &lt; testValueNumber ||
792 operator === 'greater than or equals' &amp;&amp; valsAreNumbers &amp;&amp; valueNumber >= testValueNumber ||
793 operator === 'less than or equals' &amp;&amp; valsAreNumbers &amp;&amp; valueNumber &lt;= testValueNumber
794
795 ) {
796
797 condition_ok = true;
798 break;
799
800 } else if (
801
802 operator === 'not equals' &amp;&amp; value === testValue ||
803 operator === 'not equals (regex)' &amp;&amp; regex_patt.test(value)
804
805 ) {
806
807 condition_ok = false;
808 break;
809
810 }
811 }
812
813 return condition_ok;
814
815 },
816
817 getFormObj($form) {
818 if (typeof $form === 'string') {
819 $form = jQuery($form).eq(0);
820 }
821 return wpcf7cf.getWpcf7cfForm($form);
822 },
823
824 getRepeaterObj($form, repeaterDataId) {
825 const form = wpcf7cf.getFormObj($form);
826 const repeater = form.repeaters.find( repeater => repeater.params.$repeater.attr('data-id') === repeaterDataId );
827
828 return repeater;
829
830 },
831
832 getMultiStepObj($form){
833 const form = wpcf7cf.getFormObj($form);
834 return form.multistep;
835 },
836
837 /**
838 * Append a new sub-entry to the repeater with the name `repeaterDataId` inside the form `$form`
839 * @memberof wpcf7cf
840 * @function wpcf7cf.repeaterAddSub
841 * @link
842 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
843 * @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)
844 */
845 repeaterAddSub($form,repeaterDataId) {
846 const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId);
847 repeater.updateSubs(repeater.params.$repeater.num_subs+1);
848 },
849
850 /**
851 * Insert a new sub-entry at the given `index` of the repeater with the name `repeaterDataId` inside the form `$form`
852 * @memberof wpcf7cf
853 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
854 * @param {String} repeaterDataId - *data-id* attribute of the repeater.
855 * @param {Number} index - position where to insert the new sub-entry within the repeater
856 */
857 repeaterAddSubAtIndex($form,repeaterDataId,index) {
858 const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId);
859 repeater.addSubs(1, index);
860 },
861
862 /**
863 * Remove the sub-entry at the given `index` of the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form`
864 * @memberof wpcf7cf
865 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
866 * @param {String} repeaterDataId - *data-id* attribute of the repeater.
867 * @param {Number} index - position where to insert the new sub-entry within the repeater
868 */
869 repeaterRemoveSubAtIndex($form,repeaterDataId,index) {
870 const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId);
871 repeater.removeSubs(1, index);
872 },
873
874 /**
875 * Remove the last sub-entry from the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form`
876 * @memberof wpcf7cf
877 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
878 * @param {String} repeaterDataId - *data-id* attribute of the repeater.
879 * @param {Number} index - position where to insert the new sub-entry within the repeater
880 */
881 repeaterRemoveSub($form,repeaterDataId) {
882 const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId);
883 repeater.updateSubs(repeater.params.$repeater.num_subs-1);
884 },
885
886 /**
887 * Set the number of subs for the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form`.
888 * Subs are either appended to or removed from the end of the repeater.
889 * @memberof wpcf7cf
890 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
891 * @param {String} repeaterDataId - *data-id* attribute of the repeater.
892 * @param {Number} numberOfSubs - position where to insert the new sub-entry within the repeater
893 */
894 repeaterSetNumberOfSubs($form, repeaterDataId, numberOfSubs) {
895 const repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId);
896 repeater.updateSubs(numberOfSubs);
897 },
898
899 /**
900 * Move to step number `step`, ignoring any validation.
901 * @memberof wpcf7cf
902 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
903 * @param {*} step
904 */
905 multistepMoveToStep($form, step) {
906 const multistep = wpcf7cf.getMultiStepObj($form);
907 multistep.moveToStep(step);
908 },
909
910 /**
911 * Validate the current step, and move to step number `step` if validation passes.
912 * @memberof wpcf7cf
913 * @param {String|JQuery} $form - JQuery object or css-selector representing the form
914 * @param {Number} step
915 */
916 async multistepMoveToStepWithValidation($form, step) {
917 const multistep = wpcf7cf.getMultiStepObj($form);
918
919 const result = await multistep.validateStep(multistep.currentStep);
920 if (result === 'success') {
921 multistep.moveToStep(step);
922 }
923 },
924
925
926 };
927
928 jQuery('.wpcf7-form').each(function(){
929 wpcf7cf_forms.push(new Wpcf7cfForm(jQuery(this)));
930 });
931
932 // Call displayFields again on all forms
933 // Necessary in case some theme or plugin changed a form value by the time the entire page is fully loaded.
934 jQuery('document').ready( function() {
935 wpcf7cf_forms.forEach(function(f){
936 f.displayFields();
937 });
938 });
939
940 // fix for exclusive checkboxes in IE (this will call the change-event again after all other checkboxes are unchecked, triggering the display_fields() function)
941 const old_wpcf7ExclusiveCheckbox = jQuery.fn.wpcf7ExclusiveCheckbox;
942 jQuery.fn.wpcf7ExclusiveCheckbox = function() {
943 return this.find('input:checkbox').on('click', function() {
944 const name = jQuery(this).attr('name');
945 jQuery(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false).eq(0).change();
946 });
947 };</code></pre>
948 </article>
949 </section>
950
951
952
953
954 </div>
955
956 <nav>
957 <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="wpcf7cf.html">wpcf7cf</a></li></ul>
958 </nav>
959
960 <br class="clear">
961
962 <footer>
963 Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Jun 13 2025 17:00:46 GMT+0200 (Central European Summer Time)
964 </footer>
965
966 <script> prettyPrint(); </script>
967 <script src="scripts/linenumber.js"> </script>
968 </body>
969 </html>
970