PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | js/formidable.js +291 -366 6.286.22 View file →
@@ -15,9 +15,9 @@
15 15 * @since 5.5.3
16 16 *
17 17 * @param {HTMLElement} el The HTML element.
18 18 * @param {string} eventName Event name.
19 - * @param {*} data The passed data.
19 + * @param {mixed} data The passed data.
20 20 */
21 21 function triggerCustomEvent( el, eventName, data ) {
22 22 if ( typeof window.CustomEvent !== 'function' ) {
23 23 return;
@@ -39,21 +39,24 @@
39 39 function getFieldId( field, fullID ) {
40 40 let nameParts, fieldId,
41 41 isRepeating = false,
42 42 fieldName = '';
43 -
44 43 if ( field instanceof jQuery ) {
45 - field = field.get( 0 );
44 + fieldName = field.attr( 'name' );
45 + } else {
46 + fieldName = field.name;
46 47 }
47 48
48 - fieldName = field.name;
49 -
50 49 if ( typeof fieldName === 'undefined' ) {
51 50 fieldName = '';
52 51 }
53 52
54 53 if ( fieldName === '' ) {
55 - fieldName = field.getAttribute( 'data-name' );
54 + if ( field instanceof jQuery ) {
55 + fieldName = field.data( 'name' );
56 + } else {
57 + fieldName = field.getAttribute( 'data-name' );
58 + }
56 59
57 60 if ( typeof fieldName === 'undefined' ) {
58 61 fieldName = '';
59 62 }
@@ -70,24 +73,25 @@
70 73 return 0;
71 74 }
72 75 nameParts = nameParts.filter( function( n ) {
73 76 return n !== '';
74 - } );
77 + });
75 78
76 - fieldId = nameParts[ 0 ];
79 + fieldId = nameParts[0];
77 80
78 81 if ( nameParts.length === 1 ) {
79 82 return fieldId;
80 83 }
81 84
82 - if ( nameParts[ 1 ] === '[form' || nameParts[ 1 ] === '[row_ids' ) {
85 + if ( nameParts[1] === '[form' || nameParts[1] === '[row_ids' ) {
83 86 return 0;
84 87 }
85 88
86 89 // Check if 'this' is in a repeating section
87 90 if ( document.querySelector( 'input[name="item_meta[' + fieldId + '][form]"]' ) ) {
91 +
88 92 // this is a repeatable section with name: item_meta[repeating-section-id][row-id][field-id]
89 - fieldId = nameParts[ 2 ].replace( '[', '' );
93 + fieldId = nameParts[2].replace( '[', '' );
90 94 isRepeating = true;
91 95 }
92 96
93 97 // Check if 'this' is an other text field and get field ID for it
@@ -93,21 +97,21 @@
93 97 // Check if 'this' is an other text field and get field ID for it
94 98 if ( 'other' === fieldId ) {
95 99 if ( isRepeating ) {
96 100 // name for other fields: item_meta[370][0][other][414]
97 - fieldId = nameParts[ 3 ].replace( '[', '' );
101 + fieldId = nameParts[3].replace( '[', '' );
98 102 } else {
99 103 // Other field name: item_meta[other][370]
100 - fieldId = nameParts[ 1 ].replace( '[', '' );
104 + fieldId = nameParts[1].replace( '[', '' );
101 105 }
102 106 }
103 107
104 108 if ( fullID === true ) {
105 109 // For use in the container div id
106 - if ( fieldId === nameParts[ 0 ] ) {
107 - fieldId = fieldId + '-' + nameParts[ 1 ].replace( '[', '' );
110 + if ( fieldId === nameParts[0]) {
111 + fieldId = fieldId + '-' + nameParts[1].replace( '[', '' );
108 112 } else {
109 - fieldId = fieldId + '-' + nameParts[ 0 ] + '-' + nameParts[ 1 ].replace( '[', '' );
113 + fieldId = fieldId + '-' + nameParts[0] + '-' + nameParts[1].replace( '[', '' );
110 114 }
111 115 }
112 116
113 117 return fieldId;
@@ -120,15 +124,9 @@
120 124 *
121 125 * @param {Object} $form
122 126 */
123 127 function disableSubmitButton( $form ) {
124 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
125 - if ( ! form ) {
126 - return;
127 - }
128 - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"], button.frm_save_draft' ).forEach(
129 - button => button.disabled = true
130 - );
128 + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"], button.frm_save_draft' ).attr( 'disabled', 'disabled' );
131 129 }
132 130
133 131 /**
134 132 * Enable the submit button for a given jQuery form object
@@ -134,16 +132,12 @@
134 132 * Enable the submit button for a given jQuery form object
135 133 *
136 134 * @since 2.03.02
137 135 *
138 - * @param {HTMLElement} form
139 - *
140 - * @return {void}
136 + * @param {Object} $form
141 137 */
142 - function enableSubmitButton( form ) {
143 - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"]' ).forEach(
144 - button => button.disabled = false
145 - );
138 + function enableSubmitButton( $form ) {
139 + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false );
146 140 }
147 141
148 142 /**
149 143 * Disable the save draft link for a given jQuery form object
@@ -152,33 +146,26 @@
152 146 *
153 147 * @param {Object} $form
154 148 */
155 149 function disableSaveDraft( $form ) {
156 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
157 - if ( ! form ) {
158 - return;
159 - }
160 - form.querySelectorAll( 'a.frm_save_draft' ).forEach(
161 - link => link.style.pointerEvents = 'none'
162 - );
150 + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', 'none' );
163 151 }
164 152
165 153 /**
166 - * Enable the save draft link for a given form object.
154 + * Enable the save draft link for a given jQuery form object
167 155 *
168 156 * @since 4.04.03
169 157 *
170 - * @param {jQuery|HTMLElement} $form
158 + * @param {jQuery} $form
171 159 */
172 160 function enableSaveDraft( $form ) {
173 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
174 - if ( ! form ) {
161 + if ( ! $form.length ) {
175 162 return;
176 163 }
177 - form.querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => {
178 - saveDraftButton.disabled = false;
164 + $form[0].querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => {
165 + saveDraftButton.disabled = false;
179 166 saveDraftButton.style.pointerEvents = '';
180 - } );
167 + });
181 168 }
182 169
183 170 /**
184 171 * Validate form with JS.
@@ -256,9 +243,9 @@
256 243 return;
257 244 }
258 245
259 246 fieldID = getFieldId( field, true );
260 - if ( 'undefined' === typeof errors[ fieldID ] ) {
247 + if ( 'undefined' === typeof errors[ fieldID ]) {
261 248 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
262 249 }
263 250
264 251 if ( 'function' === typeof field.reportValidity ) {
@@ -282,9 +269,9 @@
282 269 * @param {HTMLElement} field
283 270 */
284 271 function maybeValidateChange( field ) {
285 272 if ( field.type === 'url' ) {
286 - maybeAddHttpsToUrl( field );
273 + maybeAddHttpToUrl( field );
287 274 }
288 275 const form = field.closest( 'form' );
289 276 if ( form && hasClass( form, 'frm_js_validate' ) ) {
290 277 validateField( field );
@@ -293,13 +280,13 @@
293 280
294 281 /**
295 282 * @param {HTMLElement} field
296 283 */
297 - function maybeAddHttpsToUrl( field ) {
284 + function maybeAddHttpToUrl( field ) {
298 285 const url = field.value;
299 286 const matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ );
300 287 if ( field.value !== '' && matches === null ) {
301 - field.value = 'https://' + url;
288 + field.value = 'http://' + url;
302 289 }
303 290 }
304 291
305 292 /**
@@ -311,9 +298,9 @@
311 298 */
312 299 function validateField( field ) {
313 300 let errors, key;
314 301
315 - errors = [];
302 + errors = [];
316 303 const fieldContainer = field.closest( '.frm_form_field' );
317 304
318 305 if ( ! fieldContainer ) {
319 306 // Hidden fields do not have a field container and do not require JS validation.
@@ -327,12 +314,13 @@
327 314 if ( errors.length < 1 ) {
328 315 validateFieldValue( field, errors, false );
329 316 }
330 317
331 - removeFieldError( fieldContainer );
318 + const $fieldCont = jQuery( fieldContainer );
319 + removeFieldError( $fieldCont );
332 320 if ( Object.keys( errors ).length > 0 ) {
333 321 for ( key in errors ) {
334 - addFieldError( fieldContainer, key, errors );
322 + addFieldError( $fieldCont, key, errors );
335 323 }
336 324 }
337 325 }
338 326
@@ -359,12 +347,8 @@
359 347 } else if ( field.pattern !== null ) {
360 348 checkPatternField( field, errors );
361 349 }
362 350
363 - if ( 'tel' === field.type && shouldCheckConfirmField( field, onSubmit ) ) {
364 - confirmField( field, errors );
365 - }
366 -
367 351 /**
368 352 * @since 6.15 Added `onSubmit` to the data.
369 353 */
370 354 triggerCustomEvent( document, 'frm_validate_field_value', {
@@ -370,9 +354,9 @@
370 354 triggerCustomEvent( document, 'frm_validate_field_value', {
371 355 field: field,
372 356 errors: errors,
373 357 onSubmit: onSubmit
374 - } );
358 + });
375 359 }
376 360
377 361 /**
378 362 * @param {HTMLElement} field
@@ -416,10 +400,9 @@
416 400 // skip hidden other fields
417 401 return errors;
418 402 }
419 403
420 - val = jQuery( field ).val(); // eslint-disable-line no-jquery/no-val
421 -
404 + val = jQuery( field ).val();
422 405 if ( val === null ) {
423 406 val = '';
424 407 } else if ( typeof val !== 'string' ) {
425 408 tempVal = val;
@@ -424,10 +407,10 @@
424 407 } else if ( typeof val !== 'string' ) {
425 408 tempVal = val;
426 409 val = '';
427 410 for ( i = 0; i < tempVal.length; i++ ) {
428 - if ( tempVal[ i ] !== '' ) {
429 - val = tempVal[ i ];
411 + if ( tempVal[i] !== '' ) {
412 + val = tempVal[i];
430 413 }
431 414 }
432 415 }
433 416
@@ -451,11 +434,9 @@
451 434 // set id for time field
452 435 fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' );
453 436 } else if ( isSignatureField( field ) ) {
454 437 if ( val === '' ) {
455 - const fieldContainer = field.closest( '.frm_form_field' );
456 - const outputField = fieldContainer ? fieldContainer.querySelector( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ) : null;
457 - val = outputField ? outputField.value : '';
438 + val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val();
458 439 }
459 440 fieldID = fieldID.replace( '-typed', '' );
460 441 }
461 442
@@ -506,16 +487,16 @@
506 487 * @param {string|number} fileID
507 488 * @return {string} File input value.
508 489 */
509 490 function getFileVals( fileID ) {
510 - let val = '';
511 - const fileFields = document.querySelectorAll( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' );
491 + let val = '',
492 + fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' );
512 493
513 - fileFields.forEach( function( field ) {
494 + fileFields.each( function() {
514 495 if ( val === '' ) {
515 - val = field.value;
496 + val = this.value;
516 497 }
517 - } );
498 + });
518 499 return val;
519 500 }
520 501
521 502 /**
@@ -685,9 +666,9 @@
685 666 }
686 667
687 668 // Function to change the color of a select element
688 669 changeSelectColor = function( select ) {
689 - if ( select.options[ select.selectedIndex ] && hasClass( select.options[ select.selectedIndex ], 'frm-select-placeholder' ) ) {
670 + if ( select.options[select.selectedIndex] && hasClass( select.options[select.selectedIndex], 'frm-select-placeholder' ) ) {
690 671 select.style.setProperty( 'color', textColorDisabled, 'important' );
691 672 } else {
692 673 select.style.color = '';
693 674 }
@@ -700,68 +681,57 @@
700 681
701 682 // Add an event listener for future changes
702 683 select.addEventListener( 'change', function() {
703 684 changeSelectColor( select );
704 - } );
705 - } );
685 + });
686 + });
706 687 }
707 688
708 689 /**
709 690 * @param {HTMLElement|jQuery} object
710 - *
711 - * @return {HTMLElement|false} Captcha element if there is an invisible recaptcha.
691 + * @return {boolean} True if there is an invisible recaptcha.
712 692 */
713 693 function hasInvisibleRecaptcha( object ) {
694 + let recaptcha, recaptchaID, alreadyChecked;
695 +
714 696 if ( isGoingToPrevPage( object ) ) {
715 697 return false;
716 698 }
717 699
718 - const form = object instanceof jQuery ? object.get( 0 ) : object;
719 - if ( ! form ) {
720 - return false;
721 - }
722 -
723 - const recaptcha = form.querySelector( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' );
724 - if ( recaptcha ) {
725 - const recaptchaID = recaptcha.dataset.rid;
726 - const alreadyChecked = grecaptcha.getResponse( recaptchaID );
700 + recaptcha = jQuery( object ).find( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' );
701 + if ( recaptcha.length ) {
702 + recaptchaID = recaptcha.data( 'rid' );
703 + alreadyChecked = grecaptcha.getResponse( recaptchaID );
727 704 if ( alreadyChecked.length === 0 ) {
728 705 return recaptcha;
729 706 }
730 707 }
731 -
732 708 return false;
733 709 }
734 710
735 711 /**
736 - * @param {HTMLElement} invisibleRecaptcha
737 - *
738 - * @return {void}
712 + * @param {jQuery} invisibleRecaptcha
739 713 */
740 714 function executeInvisibleRecaptcha( invisibleRecaptcha ) {
741 - const recaptchaID = invisibleRecaptcha.dataset.rid;
715 + const recaptchaID = invisibleRecaptcha.data( 'rid' );
742 716 grecaptcha.reset( recaptchaID );
743 717 grecaptcha.execute( recaptchaID );
744 718 }
745 719
746 720 function validateRecaptcha( form, errors ) {
747 - const formEl = form instanceof jQuery ? form.get( 0 ) : form;
748 - if ( ! formEl ) {
749 - return errors;
750 - }
721 + let response;
751 722
752 - const recaptcha = formEl.querySelector( '.frm-g-recaptcha' );
753 - if ( ! recaptcha ) {
723 + const $recaptcha = jQuery( form ).find( '.frm-g-recaptcha' );
724 + if ( ! $recaptcha.length ) {
754 725 return errors;
755 726 }
756 727
757 - const recaptchaID = recaptcha.dataset.rid;
758 - let response;
728 + const recaptchaID = $recaptcha.data( 'rid' );
759 729
760 730 try {
761 731 response = grecaptcha.getResponse( recaptchaID );
762 732 } catch ( e ) {
763 - if ( formEl.querySelector( 'input[name="recaptcha_checked"]' ) ) {
733 + if ( jQuery( form ).find( 'input[name="recaptcha_checked"]' ).length ) {
764 734 return errors;
765 735 }
766 736 response = '';
767 737 }
@@ -766,13 +736,11 @@
766 736 response = '';
767 737 }
768 738
769 739 if ( response.length === 0 ) {
770 - const fieldContainer = recaptcha.closest( '.frm_form_field' );
771 - if ( fieldContainer && fieldContainer.id ) {
772 - const fieldID = fieldContainer.id.replace( 'frm_field_', '' ).replace( '_container', '' );
773 - errors[ fieldID ] = '';
774 - }
740 + const fieldContainer = $recaptcha.closest( '.frm_form_field' );
741 + const fieldID = fieldContainer.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_container', '' );
742 + errors[ fieldID ] = '';
775 743 }
776 744
777 745 return errors;
778 746 }
@@ -805,15 +773,15 @@
805 773 if ( null === errorHtml ) {
806 774 return msg;
807 775 }
808 776
809 - errorHtml = errorHtml.replace( /\+/g, '%20' );
810 - msg = decodeURIComponent( errorHtml ).replace( '[error]', msg );
811 - const fieldId = getFieldId( field, false );
812 - const split = fieldId.split( '-' );
777 + errorHtml = errorHtml.replace( /\+/g, '%20' );
778 + msg = decodeURIComponent( errorHtml ).replace( '[error]', msg );
779 + const fieldId = getFieldId( field, false );
780 + const split = fieldId.split( '-' );
813 781 const fieldIdParts = field.id.split( '_' );
814 782 fieldIdParts.shift(); // Drop the "field" value from the front.
815 - split[ 0 ] = fieldIdParts.join( '_' );
783 + split[0] = fieldIdParts.join( '_' );
816 784 const errorKey = split.join( '-' );
817 785 return msg.replace( '[key]', errorKey );
818 786 }
819 787
@@ -845,18 +813,18 @@
845 813 * @param {string} action
846 814 * @return {void}
847 815 */
848 816 function getFormErrors( object, action ) {
849 - let data, success, error, shouldTriggerEvent;
817 + let fieldset, data, success, error, shouldTriggerEvent;
850 818
851 - const fieldsets = object.querySelectorAll( '.frm_form_field' );
852 - fieldsets.forEach( field => field.classList.add( 'frm_doing_ajax' ) );
819 + fieldset = jQuery( object ).find( '.frm_form_field' );
820 + fieldset.addClass( 'frm_doing_ajax' );
853 821
854 - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line no-jquery/no-serialize, camelcase
822 + data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase
855 823 shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );
856 824
857 825 const doRedirect = response => {
858 - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ] );
826 + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
859 827
860 828 if ( ! response.openInNewTab ) {
861 829 // We return here because we're redirecting there is no need to update content.
862 830 window.location = response.redirect;
@@ -910,9 +878,9 @@
910 878 if ( 'string' === typeof response.content && response.content !== '' ) {
911 879 // the form or success message was returned
912 880
913 881 if ( shouldTriggerEvent ) {
914 - triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content } );
882 + triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content });
915 883 return;
916 884 }
917 885
918 886 removeSubmitLoading( jQuery( object ) );
@@ -919,17 +887,18 @@
919 887 if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase
920 888 frmFrontForm.scrollMsg( jQuery( object ), false );
921 889 }
922 890
923 - const formIdInput = object.querySelector( 'input[name="form_id"]' );
924 - formID = formIdInput ? formIdInput.value : '';
891 + formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
925 892 response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
926 - replaceContent = jQuery( object ).closest( '.frm_forms' ); // eslint-disable-line no-jquery/no-closest
893 + replaceContent = jQuery( object ).closest( '.frm_forms' );
927 894 removeAddedScripts( replaceContent, formID );
928 895 delay = maybeSlideOut( replaceContent, response.content );
929 896
930 897 setTimeout(
931 898 function() {
899 + let container, input, previousInput;
900 +
932 901 afterFormSubmittedBeforeReplace( object, response );
933 902
934 903 replaceContent.replaceWith( response.content );
935 904
@@ -935,17 +904,25 @@
935 904
936 905 addUrlParam( response );
937 906
938 907 if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
939 - const pageOrderInput = document.querySelector( 'input[name="frm_page_order_' + formID + '"]' );
940 - pageOrder = pageOrderInput ? pageOrderInput.value : '';
941 - const tempDiv = document.createElement( 'div' );
942 - tempDiv.innerHTML = response.content;
943 - const formReturnedInput = tempDiv.querySelector( 'input[name="form_id"]' );
944 - formReturned = formReturnedInput ? formReturnedInput.value : '';
908 + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
909 + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
945 910 frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
946 911 }
947 912
913 + if ( typeof response.recaptcha !== 'undefined' ) {
914 + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' );
915 + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">';
916 + previousInput = container.find( 'input[name="recaptcha_checked"]' );
917 +
918 + if ( previousInput.length ) {
919 + previousInput.replaceWith( input );
920 + } else {
921 + container.append( input );
922 + }
923 + }
924 +
948 925 afterFormSubmitted( object, response );
949 926 },
950 927 delay
951 928 );
@@ -959,14 +936,13 @@
959 936
960 937 $fieldCont = null;
961 938
962 939 for ( key in response.errors ) {
963 - const fieldContEl = object.querySelector( '#frm_field_' + key + '_container' );
964 - $fieldCont = fieldContEl ? jQuery( fieldContEl ) : jQuery();
940 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
965 941
966 942 if ( $fieldCont.length ) {
967 - if ( ! $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is
968 - inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); // eslint-disable-line no-jquery/no-closest
943 + if ( ! $fieldCont.is( ':visible' ) ) {
944 + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
969 945 if ( inCollapsedSection.length ) {
970 946 frmTrigger = inCollapsedSection.prev();
971 947 if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
972 948 // If the frmTrigger object is the section description, check to see if the previous element is the trigger
@@ -975,9 +951,9 @@
975 951 frmTrigger.trigger( 'click' );
976 952 }
977 953 }
978 954
979 - if ( $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is
955 + if ( $fieldCont.is( ':visible' ) ) {
980 956 addFieldError( $fieldCont, key, response.errors );
981 957 contSubmit = false;
982 958 }
983 959 }
@@ -982,10 +958,11 @@
982 958 }
983 959 }
984 960 }
985 961
986 - object.querySelectorAll( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).forEach( function( captchaEl ) {
987 - const recaptchaID = captchaEl.dataset.rid;
962 + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() {
963 + const $recaptcha = jQuery( this ),
964 + recaptchaID = $recaptcha.data( 'rid' );
988 965
989 966 if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
990 967 if ( recaptchaID ) {
991 968 grecaptcha.reset( recaptchaID );
@@ -992,23 +969,22 @@
992 969 } else {
993 970 grecaptcha.reset();
994 971 }
995 972 }
996 -
997 973 if ( typeof hcaptcha !== 'undefined' && hcaptcha ) {
998 974 hcaptcha.reset();
999 975 }
1000 - } );
976 + });
1001 977
1002 978 if ( window.turnstile ) {
1003 - object.querySelectorAll( '.frm-cf-turnstile' ).forEach(
979 + object.querySelectorAll( '.cf-turnstile' ).forEach(
1004 980 turnstileField => turnstileField.dataset.rid && turnstile.reset( turnstileField.dataset.rid )
1005 981 );
1006 982 }
1007 983
1008 - jQuery( document ).trigger( 'frmFormErrors', [ object, response ] );
984 + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
1009 985
1010 - fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) );
986 + fieldset.removeClass( 'frm_doing_ajax' );
1011 987 scrollToFirstField( object );
1012 988
1013 989 if ( contSubmit ) {
1014 990 object.submit();
@@ -1025,11 +1001,9 @@
1025 1001 }
1026 1002 };
1027 1003
1028 1004 error = function() {
1029 - object.querySelectorAll( 'input[type="submit"], input[type="button"]' ).forEach(
1030 - button => button.disabled = false
1031 - );
1005 + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
1032 1006 object.submit();
1033 1007 };
1034 1008
1035 1009 postToAjaxUrl( object, data, success, error );
@@ -1041,9 +1015,9 @@
1041 1015 ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase
1042 1016 action = form.getAttribute( 'action' );
1043 1017
1044 1018 if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
1045 - ajaxUrl = action.split( '?action=frm_forms_preview' )[ 0 ];
1019 + ajaxUrl = action.split( '?action=frm_forms_preview' )[0];
1046 1020 }
1047 1021
1048 1022 ajaxParams = {
1049 1023 type: 'POST',
@@ -1055,19 +1029,17 @@
1055 1029 if ( 'function' === typeof error ) {
1056 1030 ajaxParams.error = error;
1057 1031 }
1058 1032
1059 - jQuery.ajax( ajaxParams ); // eslint-disable-line no-jquery/no-ajax
1033 + jQuery.ajax( ajaxParams );
1060 1034 }
1061 1035
1062 1036 function afterFormSubmitted( object, response ) {
1063 - const tempDiv = document.createElement( 'div' );
1064 - tempDiv.innerHTML = response.content;
1065 - const formCompleted = tempDiv.querySelector( '.frm_message' );
1066 - if ( formCompleted ) {
1067 - jQuery( document ).trigger( 'frmFormComplete', [ object, response ] );
1037 + const formCompleted = jQuery( response.content ).find( '.frm_message' );
1038 + if ( formCompleted.length ) {
1039 + jQuery( document ).trigger( 'frmFormComplete', [ object, response ]);
1068 1040 } else {
1069 - jQuery( document ).trigger( 'frmPageChanged', [ object, response ] );
1041 + jQuery( document ).trigger( 'frmPageChanged', [ object, response ]);
1070 1042 }
1071 1043 }
1072 1044
1073 1045 /**
@@ -1079,21 +1051,19 @@
1079 1051 * @param {Object} response The response from submitting the form with AJAX.
1080 1052 * @return {void}
1081 1053 */
1082 1054 function afterFormSubmittedBeforeReplace( object, response ) {
1083 - const tempDiv = document.createElement( 'div' );
1084 - tempDiv.innerHTML = response.content;
1085 - const formCompleted = tempDiv.querySelector( '.frm_message' );
1086 - if ( formCompleted ) {
1087 - triggerCustomEvent( document, 'frmFormCompleteBeforeReplace', { object, response } );
1055 + const formCompleted = jQuery( response.content ).find( '.frm_message' );
1056 + if ( formCompleted.length ) {
1057 + triggerCustomEvent( document, 'frmFormCompleteBeforeReplace', { object, response });
1088 1058 }
1089 1059 }
1090 1060
1091 1061 function removeAddedScripts( formContainer, formID ) {
1092 - const endReplace = document.querySelectorAll( '.frm_end_ajax_' + formID );
1062 + const endReplace = jQuery( '.frm_end_ajax_' + formID );
1093 1063 if ( endReplace.length ) {
1094 1064 formContainer.nextUntil( '.frm_end_ajax_' + formID ).remove();
1095 - endReplace.forEach( el => el.remove() );
1065 + endReplace.remove();
1096 1066 }
1097 1067 }
1098 1068
1099 1069 function maybeSlideOut( oldContent, newContent ) {
@@ -1098,11 +1068,11 @@
1098 1068
1099 1069 function maybeSlideOut( oldContent, newContent ) {
1100 1070 let c,
1101 1071 newClass = 'frm_slideout';
1102 - if ( newContent.includes( ' frm_slide' ) ) {
1072 + if ( newContent.indexOf( ' frm_slide' ) !== -1 ) {
1103 1073 c = oldContent.children();
1104 - if ( newContent.includes( ' frm_going_back' ) ) {
1074 + if ( newContent.indexOf( ' frm_going_back' ) !== -1 ) {
1105 1075 newClass += ' frm_going_back';
1106 1076 }
1107 1077 c.removeClass( 'frm_going_back' );
1108 1078 c.addClass( newClass );
@@ -1114,9 +1084,9 @@
1114 1084 function addUrlParam( response ) {
1115 1085 let url;
1116 1086 if ( history.pushState && typeof response.page !== 'undefined' ) {
1117 1087 url = addQueryVar( 'frm_page', response.page );
1118 - window.history.pushState( { html: response.html }, '', '?' + url );
1088 + window.history.pushState({ 'html': response.html }, '', '?' + url );
1119 1089 }
1120 1090 }
1121 1091
1122 1092 function addQueryVar( key, value ) {
@@ -1128,13 +1098,13 @@
1128 1098 kvp = document.location.search.substr( 1 ).split( '&' );
1129 1099
1130 1100 i = kvp.length;
1131 1101 while ( i-- ) {
1132 - x = kvp[ i ].split( '=' );
1102 + x = kvp[i].split( '=' );
1133 1103
1134 - if ( x[ 0 ] == key ) {
1135 - x[ 1 ] = value;
1136 - kvp[ i ] = x.join( '=' );
1104 + if ( x[0] == key ) {
1105 + x[1] = value;
1106 + kvp[i] = x.join( '=' );
1137 1107 break;
1138 1108 }
1139 1109 }
1140 1110
@@ -1145,59 +1115,44 @@
1145 1115 return kvp.join( '&' );
1146 1116 }
1147 1117
1148 1118 function addFieldError( $fieldCont, key, jsErrors ) {
1149 - let id, describedBy, roleString;
1150 - const container = $fieldCont instanceof jQuery ? $fieldCont.get( 0 ) : $fieldCont;
1151 - if ( ! container || container.offsetParent === null ) {
1152 - return;
1153 - }
1119 + let input, id, describedBy, roleString;
1120 + if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) {
1121 + $fieldCont.addClass( 'frm_blank_field' );
1122 + input = $fieldCont.find( 'input, select, textarea' );
1123 + id = getErrorElementId( key, input.get( 0 ) );
1154 1124
1155 - container.classList.add( 'frm_blank_field' );
1156 - const input = container.querySelector( 'input, select, textarea' );
1157 - id = getErrorElementId( key, input );
1125 + describedBy = input.attr( 'aria-describedby' );
1158 1126
1159 - describedBy = input ? input.getAttribute( 'aria-describedby' ) : null;
1160 -
1161 - if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase
1162 - frmThemeOverride_frmPlaceError( key, jsErrors );
1163 - } else {
1164 - let errorHtml;
1165 - if ( -1 !== jsErrors[ key ].indexOf( '<div' ) ) {
1166 - errorHtml = jsErrors[ key ];
1127 + if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase
1128 + frmThemeOverride_frmPlaceError( key, jsErrors );
1167 1129 } else {
1168 - roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
1169 - errorHtml = '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[ key ] + '</div>';
1170 - }
1171 - container.insertAdjacentHTML( 'beforeend', errorHtml );
1130 + if ( -1 !== jsErrors[key].indexOf( '<div' ) ) {
1131 + $fieldCont.append(
1132 + jsErrors[key]
1133 + );
1134 + } else {
1135 + roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
1136 + $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
1137 + }
1172 1138
1173 - if ( input ) {
1174 - if ( ! describedBy ) {
1139 + if ( typeof describedBy === 'undefined' ) {
1175 1140 describedBy = id;
1176 - } else if ( ! describedBy.includes( id ) && ! describedBy.includes( 'frm_error_field_' ) ) {
1177 - const errorFirst = input.dataset.errorFirst;
1178 - if ( errorFirst === '0' ) {
1141 + } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) {
1142 + if ( input.data( 'error-first' ) === 0 ) {
1179 1143 describedBy = describedBy + ' ' + id;
1180 1144 } else {
1181 1145 describedBy = id + ' ' + describedBy;
1182 1146 }
1183 1147 }
1184 - input.setAttribute( 'aria-describedby', describedBy );
1148 +
1149 + input.attr( 'aria-describedby', describedBy );
1185 1150 }
1186 - }
1151 + input.attr( 'aria-invalid', true );
1187 1152
1188 - if ( input ) {
1189 - if ( [ 'radio', 'checkbox' ].includes( input.type ) ) {
1190 - const group = input.closest( '[role="radiogroup"], [role="group"]' );
1191 - if ( group ) {
1192 - group.setAttribute( 'aria-invalid', 'true' );
1193 - }
1194 - } else {
1195 - input.setAttribute( 'aria-invalid', 'true' );
1196 - }
1153 + jQuery( document ).trigger( 'frmAddFieldError', [ $fieldCont, key, jsErrors ]);
1197 1154 }
1198 -
1199 - jQuery( document ).trigger( 'frmAddFieldError', [ jQuery( container ), key, jsErrors ] );
1200 1155 }
1201 1156
1202 1157 /**
1203 1158 * Get the ID to use for an error element added when submitting with AJAX.
@@ -1217,56 +1172,36 @@
1217 1172 /**
1218 1173 * Removes errors before validating with JS.
1219 1174 * This prevents issues with stale errors that has since been fixed.
1220 1175 *
1221 - * @param {HTMLElement|jQuery} fieldCont Field container element.
1176 + * @param {Object} $fieldCont jQuery object.
1222 1177 * @return {void}
1223 1178 */
1224 - function removeFieldError( fieldCont ) {
1225 - const container = fieldCont instanceof jQuery ? fieldCont.get( 0 ) : fieldCont;
1226 - if ( ! container ) {
1227 - return;
1228 - }
1179 + function removeFieldError( $fieldCont ) {
1180 + const errorMessage = $fieldCont.find( '.frm_error' );
1181 + const errorId = errorMessage.attr( 'id' );
1182 + const input = $fieldCont.find( 'input, select, textarea' );
1183 + let describedBy = input.attr( 'aria-describedby' );
1229 1184
1230 - const errorMessage = container.querySelector( '.frm_error' );
1231 - const errorId = errorMessage ? errorMessage.id : '';
1232 - const input = container.querySelector( 'input, select, textarea' );
1233 - let describedBy = input ? input.getAttribute( 'aria-describedby' ) : null;
1234 -
1235 - container.classList.remove( 'frm_blank_field', 'has-error' );
1236 -
1237 - if ( input ) {
1238 - if ( 'true' === input.getAttribute( 'aria-invalid' ) ) {
1239 - input.setAttribute( 'aria-invalid', 'false' );
1240 - } else if ( [ 'radio', 'checkbox' ].includes( input.type ) ) {
1241 - const group = input.closest( '[role="radiogroup"], [role="group"]' );
1242 - if ( group ) {
1243 - group.setAttribute( 'aria-invalid', 'false' );
1244 - }
1245 - }
1185 + const fieldContainer = $fieldCont.get( 0 );
1186 + if ( fieldContainer && fieldContainer.classList ) {
1187 + fieldContainer.classList.remove( 'frm_blank_field', 'has-error' );
1246 1188 }
1247 1189
1248 - if ( errorMessage ) {
1249 - errorMessage.remove();
1250 - }
1190 + errorMessage.remove();
1191 + input.attr( 'aria-invalid', false );
1192 + input.removeAttr( 'aria-describedby' );
1251 1193
1252 - if ( input ) {
1253 - input.removeAttribute( 'aria-describedby' );
1254 - if ( describedBy ) {
1255 - describedBy = describedBy.replace( errorId, '' ).trim();
1256 - if ( describedBy ) {
1257 - input.setAttribute( 'aria-describedby', describedBy );
1258 - }
1259 - }
1194 + if ( typeof describedBy !== 'undefined' ) {
1195 + describedBy = describedBy.replace( errorId, '' );
1196 + input.attr( 'aria-describedby', describedBy );
1260 1197 }
1261 1198 }
1262 1199
1263 1200 function removeAllErrors() {
1264 - document.querySelectorAll( '.form-field' ).forEach( field => {
1265 - field.classList.remove( 'frm_blank_field', 'has-error' );
1266 - } );
1267 - document.querySelectorAll( '.form-field .frm_error' ).forEach( error => error.remove() );
1268 - document.querySelectorAll( '.frm_error_style' ).forEach( error => error.remove() );
1201 + jQuery( '.form-field' ).removeClass( 'frm_blank_field has-error' );
1202 + jQuery( '.form-field .frm_error' ).replaceWith( '' );
1203 + jQuery( '.frm_error_style' ).remove();
1269 1204 }
1270 1205
1271 1206 /**
1272 1207 * @param {HTMLElement|Object} object Form object.
@@ -1289,9 +1224,9 @@
1289 1224 disableSaveDraft( $object );
1290 1225 }
1291 1226
1292 1227 function showLoadingIndicator( $object ) {
1293 - if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) { // eslint-disable-line no-jquery/no-class
1228 + if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) {
1294 1229 addLoadingClass( $object );
1295 1230 $object.trigger( 'frmStartFormLoading' );
1296 1231 }
1297 1232 }
@@ -1298,9 +1233,9 @@
1298 1233
1299 1234 function addLoadingClass( $object ) {
1300 1235 const loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form';
1301 1236
1302 - $object.addClass( loadingClass ); // eslint-disable-line no-jquery/no-class
1237 + $object.addClass( loadingClass );
1303 1238 }
1304 1239
1305 1240 function isGoingToPrevPage( $object ) {
1306 1241 return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) );
@@ -1306,36 +1241,37 @@
1306 1241 return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) );
1307 1242 }
1308 1243
1309 1244 function removeSubmitLoading( _, enable, processesRunning ) {
1245 + let loadingForm;
1246 +
1310 1247 if ( processesRunning > 0 ) {
1311 1248 return;
1312 1249 }
1313 1250
1314 - document.querySelectorAll( '.frm_loading_form' ).forEach( function( form ) {
1315 - form.classList.remove( 'frm_loading_form', 'frm_loading_prev' );
1316 - jQuery( form ).trigger( 'frmEndFormLoading' );
1251 + loadingForm = jQuery( '.frm_loading_form' );
1252 + loadingForm.removeClass( 'frm_loading_form' );
1253 + loadingForm.removeClass( 'frm_loading_prev' );
1317 1254
1318 - if ( enable === 'enable' ) {
1319 - enableSubmitButton( form );
1320 - enableSaveDraft( form );
1321 - }
1322 - } );
1255 + loadingForm.trigger( 'frmEndFormLoading' );
1256 +
1257 + if ( enable === 'enable' ) {
1258 + enableSubmitButton( loadingForm );
1259 + enableSaveDraft( loadingForm );
1260 + }
1323 1261 }
1324 1262
1325 1263 function showFileLoading( object ) {
1326 - const loading = document.getElementById( 'frm_loading' );
1327 - if ( loading === null ) {
1328 - return;
1264 + let fileval,
1265 + loading = document.getElementById( 'frm_loading' );
1266 + if ( loading !== null ) {
1267 + fileval = jQuery( object ).find( 'input[type=file]' ).val();
1268 + if ( typeof fileval !== 'undefined' && fileval !== '' ) {
1269 + setTimeout( function() {
1270 + jQuery( loading ).fadeIn( 'slow' );
1271 + }, 2000 );
1272 + }
1329 1273 }
1330 -
1331 - const fileInput = object.querySelector( 'input[type=file]' );
1332 - const fileval = fileInput ? fileInput.value : '';
1333 - if ( fileval !== '' ) {
1334 - setTimeout( function() {
1335 - jQuery( loading ).fadeIn( 'slow' ); // eslint-disable-line no-jquery/no-fade
1336 - }, 2000 );
1337 - }
1338 1274 }
1339 1275
1340 1276 /**********************************************
1341 1277 * General Helpers
@@ -1342,9 +1278,9 @@
1342 1278 *********************************************/
1343 1279
1344 1280 function confirmClick() {
1345 1281 /*jshint validthis:true */
1346 - const message = this.dataset.frmconfirm;
1282 + const message = jQuery( this ).data( 'frmconfirm' );
1347 1283 return confirm( message );
1348 1284 }
1349 1285
1350 1286 /**
@@ -1352,12 +1288,11 @@
1352 1288 * If this is a match, the User is autofilling the input on a Webkit browser.
1353 1289 * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
1354 1290 */
1355 1291 function onHoneypotFieldChange() {
1356 - /*jshint validthis:true */
1357 - const css = window.getComputedStyle( this ).boxShadow;
1358 - if ( css && css.match( /inset/ ) ) {
1359 - this.remove();
1292 + const css = jQuery( this ).css( 'box-shadow' );
1293 + if ( css.match( /inset/ ) ) {
1294 + this.parentNode.removeChild( this );
1360 1295 }
1361 1296 }
1362 1297
1363 1298 /**
@@ -1380,10 +1315,10 @@
1380 1315 }
1381 1316
1382 1317 label.addEventListener( 'click', function() {
1383 1318 inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus();
1384 - } );
1385 - } );
1319 + });
1320 + });
1386 1321 }
1387 1322
1388 1323 /**
1389 1324 * Sets focus on a the first subfield of a combo field that has an error.
@@ -1419,9 +1354,9 @@
1419 1354 if ( ! errors.length ) {
1420 1355 return;
1421 1356 }
1422 1357
1423 - element = errors[ 0 ];
1358 + element = errors[0];
1424 1359 do {
1425 1360 element = element.previousSibling;
1426 1361 if ( -1 !== [ 'input', 'select', 'textarea' ].indexOf( element.nodeName.toLowerCase() ) ) {
1427 1362 focusInput( element );
@@ -1471,9 +1406,9 @@
1471 1406 function focusInput( input ) {
1472 1407 if ( input.offsetParent !== null ) {
1473 1408 input.focus();
1474 1409 } else {
1475 - triggerCustomEvent( document, 'frmMaybeDelayFocus', { input } );
1410 + triggerCustomEvent( document, 'frmMaybeDelayFocus', { input });
1476 1411 }
1477 1412 }
1478 1413
1479 1414 /**
@@ -1495,9 +1430,9 @@
1495 1430 let target;
1496 1431
1497 1432 // loop parent nodes from the target to the delegation node.
1498 1433 for ( target = e.target; target && target != this; target = target.parentNode ) {
1499 - if ( target.matches && target.matches( selector ) ) {
1434 + if ( target && target.matches && target.matches( selector ) ) {
1500 1435 handler.call( target, e );
1501 1436 break;
1502 1437 }
1503 1438 }
@@ -1506,9 +1441,9 @@
1506 1441
1507 1442 function initFloatingLabels() {
1508 1443 let checkFloatLabel, checkDropdownLabel, runOnLoad, selector, floatClass;
1509 1444
1510 - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1445 + selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1511 1446 floatClass = 'frm_label_float_top';
1512 1447
1513 1448 checkFloatLabel = function( input ) {
1514 1449 let container, shouldFloatTop, firstOpt;
@@ -1544,9 +1479,9 @@
1544 1479 if ( firstOpt.textContent ) {
1545 1480 firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1546 1481 firstOpt.textContent = '';
1547 1482 }
1548 - } );
1483 + });
1549 1484 };
1550 1485
1551 1486 [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
1552 1487 documentOn(
@@ -1556,10 +1491,14 @@
1556 1491 checkFloatLabel( event.target );
1557 1492 },
1558 1493 true
1559 1494 );
1560 - } );
1495 + });
1561 1496
1497 + jQuery( document ).on( 'change', selector, function( event ) {
1498 + checkFloatLabel( event.target );
1499 + });
1500 +
1562 1501 runOnLoad = function( firstLoad ) {
1563 1502 if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) {
1564 1503 checkFloatLabel( document.activeElement );
1565 1504 } else if ( firstLoad ) {
@@ -1579,13 +1518,13 @@
1579 1518 runOnLoad( true );
1580 1519
1581 1520 jQuery( document ).on( 'frmPageChanged', function( event ) {
1582 1521 runOnLoad();
1583 - } );
1522 + });
1584 1523
1585 1524 document.addEventListener( 'frm_after_start_over', function( event ) {
1586 1525 runOnLoad();
1587 - } );
1526 + });
1588 1527 }
1589 1528
1590 1529 function shouldUpdateValidityMessage( target ) {
1591 1530 if ( 'INPUT' !== target.nodeName ) {
@@ -1622,9 +1561,9 @@
1622 1561 if ( 'valid' !== key && field.validity[ key ] === true ) {
1623 1562 isInvalid = true;
1624 1563 break;
1625 1564 }
1626 - }
1565 + };
1627 1566
1628 1567 if ( ! isInvalid ) {
1629 1568 field.setCustomValidity( '' );
1630 1569 }
@@ -1647,9 +1586,9 @@
1647 1586
1648 1587 function setCustomValidityMessage() {
1649 1588 let forms, length, index;
1650 1589
1651 - forms = document.getElementsByClassName( 'frm-show-form' );
1590 + forms = document.getElementsByClassName( 'frm-show-form' );
1652 1591 length = forms.length;
1653 1592
1654 1593 for ( index = 0; index < length; ++index ) {
1655 1594 forms[ index ].addEventListener(
@@ -1670,14 +1609,14 @@
1670 1609 window.addEventListener( 'pageshow', function( event ) {
1671 1610 if ( event.persisted ) {
1672 1611 document.querySelectorAll( '.frm_loading_form' ).forEach(
1673 1612 function( form ) {
1674 - enableSubmitButton( form );
1613 + enableSubmitButton( jQuery( form ) );
1675 1614 }
1676 1615 );
1677 1616 removeSubmitLoading();
1678 1617 }
1679 - } );
1618 + });
1680 1619 }
1681 1620
1682 1621 /**
1683 1622 * Destroys the formidable generated global hcaptcha object since it wouldn't otherwise render.
@@ -1719,11 +1658,11 @@
1719 1658 }
1720 1659
1721 1660 /* eslint-disable compat/compat */
1722 1661 const startTime = performance.now();
1723 - const step = currentTime => {
1662 + const step = ( currentTime ) => {
1724 1663 const progress = Math.min( ( currentTime - startTime ) / duration, 1 );
1725 - document.documentElement.scrollTop = start + ( ( end - start ) * progress );
1664 + document.documentElement.scrollTop = start + ( end - start ) * progress;
1726 1665 if ( progress < 1 ) {
1727 1666 requestAnimationFrame( step );
1728 1667 }
1729 1668 };
@@ -1730,37 +1669,19 @@
1730 1669 requestAnimationFrame( step );
1731 1670 /* eslint-enable compat/compat */
1732 1671 }
1733 1672
1734 - /**
1735 - * Make sure that the captcha label for a reCAPTCHA or Turnstile field matches the response input ID.
1736 - * This is determined dynamically, so we check for the ID after the input is rendered.
1737 - * hCaptcha is handled separately, in the frmCaptcha function as it is not rendered explicitly.
1738 - *
1739 - * @since 6.25.1
1740 - *
1741 - * @param {HTMLElement} captcha
1742 - * @return {void}
1743 - */
1744 - function maybeFixCaptchaLabel( captcha ) {
1745 - const form = captcha.closest( 'form' );
1746 - if ( ! form ) {
1747 - return;
1748 - }
1749 -
1750 - const label = form.querySelector( 'label[for="g-recaptcha-response"], label[for="cf-turnstile-response"]' );
1751 - const captchaResponse = form.querySelector( '[name="g-recaptcha-response"], [name="cf-turnstile-response"]' );
1752 -
1753 - if ( label && captchaResponse ) {
1754 - label.htmlFor = captchaResponse.id;
1755 - }
1756 - }
1757 -
1758 1673 return {
1759 1674 init: function() {
1760 1675 jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1761 1676 jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
1762 1677
1678 + jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
1679 + if ( jQuery( this ).val() === '' ) {
1680 + jQuery( this ).trigger( 'blur' );
1681 + }
1682 + });
1683 +
1763 1684 jQuery( document ).on( 'change', '.frm-show-form input[name^="item_meta"], .frm-show-form select[name^="item_meta"], .frm-show-form textarea[name^="item_meta"]', frmFrontForm.fieldValueChanged );
1764 1685
1765 1686 jQuery( document ).on( 'change', '.frm_verify[id^=field_]', onHoneypotFieldChange );
1766 1687
@@ -1804,9 +1725,9 @@
1804 1725 if ( rendered ) {
1805 1726 return;
1806 1727 }
1807 1728
1808 - const size = captcha.getAttribute( 'data-size' );
1729 + const size = captcha.getAttribute( 'data-size' );
1809 1730 const params = {
1810 1731 sitekey: captcha.getAttribute( 'data-sitekey' ),
1811 1732 size: size,
1812 1733 theme: captcha.getAttribute( 'data-theme' )
@@ -1824,25 +1745,22 @@
1824 1745 frmFrontForm.afterRecaptcha( token, formID );
1825 1746 };
1826 1747 }
1827 1748
1828 - const activeCaptcha = getSelectedCaptcha( captchaSelector );
1749 + const activeCaptcha = getSelectedCaptcha( captchaSelector );
1829 1750 const captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? '#' + captcha.id : captcha.id;
1830 - const captchaID = activeCaptcha.render( captchaContainer, params );
1751 + const captchaID = activeCaptcha.render( captchaContainer, params );
1831 1752
1832 1753 captcha.setAttribute( 'data-rid', captchaID );
1833 -
1834 - maybeFixCaptchaLabel( captcha );
1835 1754 },
1836 1755
1837 1756 afterSingleRecaptcha: function() {
1838 - const recaptcha = document.querySelector( '.frm-show-form .g-recaptcha' );
1839 - const object = recaptcha ? recaptcha.closest( 'form' ) : null;
1757 + const object = jQuery( '.frm-show-form .g-recaptcha' ).closest( 'form' )[0];
1840 1758 frmFrontForm.submitFormNow( object );
1841 1759 },
1842 1760
1843 1761 afterRecaptcha: function( _, formID ) {
1844 - const object = document.querySelector( '#frm_form_' + formID + '_container form' );
1762 + const object = jQuery( '#frm_form_' + formID + '_container form' )[0];
1845 1763 frmFrontForm.submitFormNow( object );
1846 1764 },
1847 1765
1848 1766 submitForm: function( e ) {
@@ -1854,9 +1772,20 @@
1854 1772 * @param {HTMLElement} object The form object that is being submitted.
1855 1773 * @return {void}
1856 1774 */
1857 1775 submitFormManual: function( e, object ) {
1858 - if ( document.body.classList.contains( 'wp-admin' ) && ! object.closest( '.frmapi-form' ) ) {
1776 + let isPro, errors,
1777 + invisibleRecaptcha = hasInvisibleRecaptcha( object ),
1778 + classList = object.className.trim().split( /\s+/gi );
1779 +
1780 + if ( classList && invisibleRecaptcha.length < 1 ) {
1781 + isPro = classList.indexOf( 'frm_pro_form' ) > -1;
1782 + if ( ! isPro ) {
1783 + return;
1784 + }
1785 + }
1786 +
1787 + if ( jQuery( 'body' ).hasClass( 'wp-admin' ) && jQuery( object ).closest( '.frmapi-form' ).length < 1 ) {
1859 1788 return;
1860 1789 }
1861 1790
1862 1791 e.preventDefault();
@@ -1864,22 +1793,21 @@
1864 1793 if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' && ! frmProForm.submitAllowed( object ) ) {
1865 1794 return;
1866 1795 }
1867 1796
1868 - const errors = frmFrontForm.validateFormSubmit( object );
1797 + errors = frmFrontForm.validateFormSubmit( object );
1869 1798 if ( Object.keys( errors ).length !== 0 ) {
1870 1799 return;
1871 1800 }
1872 1801
1873 - const invisibleRecaptcha = hasInvisibleRecaptcha( object );
1874 -
1875 - if ( invisibleRecaptcha ) {
1802 + if ( invisibleRecaptcha.length ) {
1876 1803 showLoadingIndicator( jQuery( object ) );
1877 1804 executeInvisibleRecaptcha( invisibleRecaptcha );
1878 1805 } else {
1806 +
1879 1807 showSubmitLoading( jQuery( object ) );
1880 1808
1881 - frmFrontForm.submitFormNow( object );
1809 + frmFrontForm.submitFormNow( object, classList );
1882 1810 }
1883 1811 },
1884 1812
1885 1813 submitFormNow: function( object ) {
@@ -1891,24 +1819,24 @@
1891 1819 antispamInput = document.createElement( 'input' );
1892 1820 antispamInput.type = 'hidden';
1893 1821 antispamInput.name = 'antispam_token';
1894 1822 antispamInput.value = object.getAttribute( 'data-token' );
1895 - object.append( antispamInput );
1823 + object.appendChild( antispamInput );
1896 1824 }
1897 1825
1898 1826 // Add a unique ID, used for duplicate checks.
1899 1827 const uniqueIDInput = document.createElement( 'input' );
1900 - uniqueIDInput.type = 'hidden';
1901 - uniqueIDInput.name = 'unique_id';
1828 + uniqueIDInput.type = 'hidden';
1829 + uniqueIDInput.name = 'unique_id';
1902 1830 uniqueIDInput.value = getUniqueKey();
1903 - object.append( uniqueIDInput );
1831 + object.appendChild( uniqueIDInput );
1904 1832
1905 - if ( classList.includes( 'frm_ajax_submit' ) ) {
1906 - const fileInputs = object.querySelectorAll( 'input[type="file"]' );
1907 - hasFileFields = Array.from( fileInputs ).filter( input => !! input.value ).length;
1833 + if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) {
1834 + hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() {
1835 + return !! this.value;
1836 + }).length;
1908 1837 if ( hasFileFields < 1 ) {
1909 - const actionInput = object.querySelector( 'input[name="frm_action"]' );
1910 - const action = actionInput ? actionInput.value : '';
1838 + const action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
1911 1839 frmFrontForm.checkFormErrors( object, action );
1912 1840 } else {
1913 1841 object.submit();
1914 1842 }
@@ -1922,10 +1850,9 @@
1922 1850 *
1923 1851 * @return {Array} List of errors.
1924 1852 */
1925 1853 validateFormSubmit: function( object ) {
1926 - const form = object instanceof jQuery ? object.get( 0 ) : object;
1927 - if ( typeof tinyMCE !== 'undefined' && form && form.querySelector( '.wp-editor-wrap' ) ) {
1854 + if ( typeof tinyMCE !== 'undefined' && jQuery( object ).find( '.wp-editor-wrap' ).length ) {
1928 1855 tinyMCE.triggerSave();
1929 1856 }
1930 1857
1931 1858 jsErrors = [];
@@ -1946,16 +1873,14 @@
1946 1873 * @return {Array} List of errors.
1947 1874 */
1948 1875 getAjaxFormErrors: function( object ) {
1949 1876 let customErrors, key;
1950 - const form = object instanceof jQuery ? object.get( 0 ) : object;
1951 1877
1952 1878 jsErrors = validateForm( object );
1953 1879 if ( typeof frmThemeOverride_jsErrors === 'function' ) { // eslint-disable-line camelcase
1954 - const actionInput = form ? form.querySelector( 'input[name="frm_action"]' ) : null;
1955 - const action = actionInput ? actionInput.value : '';
1880 + const action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
1956 1881 customErrors = frmThemeOverride_jsErrors( action, object );
1957 - if ( Object.keys( customErrors ).length ) {
1882 + if ( Object.keys( customErrors ).length ) {
1958 1883 for ( key in customErrors ) {
1959 1884 jsErrors[ key ] = customErrors[ key ];
1960 1885 }
1961 1886 }
@@ -1963,9 +1888,9 @@
1963 1888
1964 1889 triggerCustomEvent( document, 'frm_get_ajax_form_errors', {
1965 1890 formEl: object,
1966 1891 errors: jsErrors
1967 - } );
1892 + });
1968 1893
1969 1894 return jsErrors;
1970 1895 },
1971 1896
@@ -1973,17 +1898,16 @@
1973 1898 * @param {HTMLElement|Object} object Form object. This might be a jQuery object.
1974 1899 * @return {void}
1975 1900 */
1976 1901 addAjaxFormErrors: function( object ) {
1977 - let key;
1978 - const form = object instanceof jQuery ? object.get( 0 ) : object;
1902 + let key, $fieldCont;
1979 1903 removeAllErrors();
1980 1904
1981 1905 for ( key in jsErrors ) {
1982 - const fieldCont = form ? form.querySelector( '#frm_field_' + key + '_container' ) : null;
1906 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
1983 1907
1984 - if ( fieldCont ) {
1985 - addFieldError( fieldCont, key, jsErrors );
1908 + if ( $fieldCont.length ) {
1909 + addFieldError( $fieldCont, key, jsErrors );
1986 1910 } else {
1987 1911 // we are unable to show the error, so remove it
1988 1912 delete jsErrors[ key ];
1989 1913 }
@@ -2011,11 +1935,9 @@
2011 1935 if ( scrollObj.length < 1 ) {
2012 1936 return;
2013 1937 }
2014 1938 } else if ( typeof id === 'string' ) {
2015 - const formEl = object instanceof jQuery ? object.get( 0 ) : object;
2016 - const fieldEl = formEl ? formEl.querySelector( '#frm_field_' + id + '_container' ) : null;
2017 - scrollObj = fieldEl ? jQuery( fieldEl ) : jQuery();
1939 + scrollObj = jQuery( object ).find( '#frm_field_' + id + '_container' );
2018 1940 } else {
2019 1941 scrollObj = id;
2020 1942 }
2021 1943
@@ -2025,10 +1947,10 @@
2025 1947 return;
2026 1948 }
2027 1949 newPos = newPos - frm_js.offset; // eslint-disable-line camelcase
2028 1950
2029 - m = getComputedStyle( document.documentElement ).marginTop;
2030 - b = getComputedStyle( document.body ).marginTop;
1951 + m = jQuery( 'html' ).css( 'margin-top' );
1952 + b = jQuery( 'body' ).css( 'margin-top' );
2031 1953 if ( m || b ) {
2032 1954 newPos = newPos - parseInt( m ) - parseInt( b );
2033 1955 }
2034 1956
@@ -2051,9 +1973,9 @@
2051 1973 fieldValueChanged: function( e ) {
2052 1974 /*jshint validthis:true */
2053 1975
2054 1976 const fieldId = frmFrontForm.getFieldId( this, false );
2055 - if ( ! fieldId ) {
1977 + if ( ! fieldId || typeof fieldId === 'undefined' ) {
2056 1978 return;
2057 1979 }
2058 1980
2059 1981 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
@@ -2059,9 +1981,9 @@
2059 1981 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
2060 1982 return;
2061 1983 }
2062 1984
2063 - jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ] );
1985 + jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]);
2064 1986
2065 1987 if ( e.selfTriggered !== true ) {
2066 1988 maybeValidateChange( this );
2067 1989 }
@@ -2076,8 +1998,30 @@
2076 1998 .replace( /"/g, '&quot;' )
2077 1999 .replace( /'/g, '&#039;' );
2078 2000 },
2079 2001
2002 + /**
2003 + * This function was used in old back end code in v2.0.
2004 + *
2005 + * @param {string} classes
2006 + * @return {void}
2007 + */
2008 + invisible: function( classes ) {
2009 + console.warn( 'DEPRECATED: function frmFrontForm.invisible in v6.16.3' );
2010 + jQuery( classes ).css( 'visibility', 'hidden' );
2011 + },
2012 +
2013 + /**
2014 + * This function was used in old back end code in v2.0.
2015 + *
2016 + * @param {string} classes
2017 + * @return {void}
2018 + */
2019 + visible: function( classes ) {
2020 + console.warn( 'DEPRECATED: function frmFrontForm.visible in v6.16.3' );
2021 + jQuery( classes ).css( 'visibility', 'visible' );
2022 + },
2023 +
2080 2024 triggerCustomEvent: triggerCustomEvent,
2081 2025 documentOn
2082 2026 };
2083 2027 }
@@ -2085,45 +2029,26 @@
2085 2029 window.frmFrontForm = frmFrontFormJS();
2086 2030
2087 2031 jQuery( document ).ready( function() {
2088 2032 frmFrontForm.init();
2089 -} );
2033 +});
2090 2034
2091 2035 function frmRecaptcha() {
2092 2036 frmCaptcha( '.frm-g-recaptcha' );
2093 2037 }
2094 2038
2095 -function frmHcaptcha() {
2096 - frmCaptcha( '.h-captcha' );
2097 -}
2098 -
2099 2039 function frmTurnstile() {
2100 - frmCaptcha( '.frm-cf-turnstile' );
2040 + frmCaptcha( '.cf-turnstile' );
2101 2041 }
2102 2042
2103 2043 function frmCaptcha( captchaSelector ) {
2104 - if ( '.h-captcha' === captchaSelector ) {
2105 - // hCaptcha is still rendered implicitly, so we only want to handle the label and exit early.
2106 - // Match the hcaptcha labels to the hcaptcha response fields.
2107 - const captchaLabels = document.querySelectorAll( 'label[for="h-captcha-response"]' );
2108 - if ( captchaLabels.length ) {
2109 - captchaLabels.forEach( label => {
2110 - const captchaResponse = label.closest( 'form' )?.querySelector( '[name="h-captcha-response"]' );
2111 - if ( captchaResponse ) {
2112 - label.htmlFor = captchaResponse.id;
2113 - }
2114 - } );
2115 - }
2116 - return;
2117 - }
2118 -
2119 2044 let c;
2120 2045 const captchas = document.querySelectorAll( captchaSelector );
2121 - const cl = captchas.length;
2046 + const cl = captchas.length;
2122 2047 for ( c = 0; c < cl; c++ ) {
2123 - const closestForm = captchas[ c ].closest( 'form' );
2048 + const closestForm = captchas[c].closest( 'form' );
2124 2049 const formIsVisible = closestForm && closestForm.offsetParent !== null;
2125 - const captcha = captchas[ c ];
2050 + const captcha = captchas[c];
2126 2051 if ( ! formIsVisible ) {
2127 2052 // If the form is not visible, try again later in 400ms.
2128 2053 // This fixes issues where the form fades visible on page load.
2129 2054 // Or whne the form is inside of a modal.
@@ -2145,9 +2070,9 @@
2145 2070 function getSelectedCaptcha( captchaSelector ) {
2146 2071 if ( captchaSelector === '.frm-g-recaptcha' ) {
2147 2072 return grecaptcha;
2148 2073 }
2149 - if ( document.querySelector( '.frm-cf-turnstile' ) ) {
2074 + if ( document.querySelector( '.cf-turnstile' ) ) {
2150 2075 return turnstile;
2151 2076 }
2152 2077 return hcaptcha;
2153 2078 }