| @@ -1,59 +1,51 @@ | ||
| 1 | -/* exported frmRecaptcha, frmAfterRecaptcha */ | |
| 2 | -/* eslint-disable prefer-const */ | |
| 1 | +/* exported frmRecaptcha, frmAfterRecaptcha, frmUpdateField, frmDeleteEntry, frmOnSubmit, frm_resend_email */ | |
| 3 | 2 | |
| 3 | +var frmFrontForm; | |
| 4 | + | |
| 4 | 5 | function frmFrontFormJS() { |
| 5 | 6 | 'use strict'; |
| 6 | 7 | |
| 7 | - /*global jQuery:false, frm_js, grecaptcha, hcaptcha, turnstile, frmProForm, tinyMCE */ | |
| 8 | + /*global jQuery:false, frm_js, grecaptcha, frmProForm, tinyMCE */ | |
| 8 | 9 | /*global frmThemeOverride_jsErrors, frmThemeOverride_frmPlaceError, frmThemeOverride_frmAfterSubmit */ |
| 9 | 10 | |
| 10 | - let jsErrors = []; | |
| 11 | + var action = ''; | |
| 12 | + var jsErrors = []; | |
| 11 | 13 | |
| 12 | - /** | |
| 13 | - * Triggers custom JS event. | |
| 14 | - * | |
| 15 | - * @since 5.5.3 | |
| 16 | - * | |
| 17 | - * @param {HTMLElement} el The HTML element. | |
| 18 | - * @param {string} eventName Event name. | |
| 19 | - * @param {*} data The passed data. | |
| 20 | - */ | |
| 21 | - function triggerCustomEvent( el, eventName, data ) { | |
| 22 | - if ( typeof window.CustomEvent !== 'function' ) { | |
| 23 | - return; | |
| 14 | + function maybeShowLabel() { | |
| 15 | + /*jshint validthis:true */ | |
| 16 | + var $field = jQuery( this ), | |
| 17 | + $label = $field.closest( '.frm_inside_container' ).find( '.frm_primary_label' ), | |
| 18 | + val = $field.val(); | |
| 19 | + | |
| 20 | + if ( val !== null && val.length > 0 ) { | |
| 21 | + $label.addClass( 'frm_visible' ); | |
| 22 | + } else { | |
| 23 | + $label.removeClass( 'frm_visible' ); | |
| 24 | 24 | } |
| 25 | - | |
| 26 | - const event = new CustomEvent( eventName ); | |
| 27 | - event.frmData = data; | |
| 28 | - | |
| 29 | - el.dispatchEvent( event ); | |
| 30 | 25 | } |
| 31 | 26 | |
| 32 | - /** | |
| 33 | - * Get the ID of the field that changed. | |
| 34 | - * | |
| 35 | - * @param {HTMLElement|jQuery} field | |
| 36 | - * @param {boolean} fullID | |
| 37 | - * @return {string|number} Field ID. | |
| 38 | - */ | |
| 27 | + /* Get the ID of the field that changed*/ | |
| 39 | 28 | function getFieldId( field, fullID ) { |
| 40 | - let nameParts, fieldId, | |
| 29 | + var nameParts, fieldId, | |
| 41 | 30 | isRepeating = false, |
| 42 | 31 | fieldName = ''; |
| 43 | - | |
| 44 | 32 | if ( field instanceof jQuery ) { |
| 45 | - field = field.get( 0 ); | |
| 33 | + fieldName = field.attr( 'name' ); | |
| 34 | + } else { | |
| 35 | + fieldName = field.name; | |
| 46 | 36 | } |
| 47 | 37 | |
| 48 | - fieldName = field.name; | |
| 49 | - | |
| 50 | 38 | if ( typeof fieldName === 'undefined' ) { |
| 51 | 39 | fieldName = ''; |
| 52 | 40 | } |
| 53 | 41 | |
| 54 | 42 | if ( fieldName === '' ) { |
| 55 | - fieldName = field.getAttribute( 'data-name' ); | |
| 43 | + if ( field instanceof jQuery ) { | |
| 44 | + fieldName = field.data( 'name' ); | |
| 45 | + } else { | |
| 46 | + fieldName = field.getAttribute( 'data-name' ); | |
| 47 | + } | |
| 56 | 48 | |
| 57 | 49 | if ( typeof fieldName === 'undefined' ) { |
| 58 | 50 | fieldName = ''; |
| 59 | 51 | } |
| @@ -70,24 +62,25 @@ | ||
| 70 | 62 | return 0; |
| 71 | 63 | } |
| 72 | 64 | nameParts = nameParts.filter( function( n ) { |
| 73 | 65 | return n !== ''; |
| 74 | - } ); | |
| 66 | + }); | |
| 75 | 67 | |
| 76 | - fieldId = nameParts[ 0 ]; | |
| 68 | + fieldId = nameParts[0]; | |
| 77 | 69 | |
| 78 | 70 | if ( nameParts.length === 1 ) { |
| 79 | 71 | return fieldId; |
| 80 | 72 | } |
| 81 | 73 | |
| 82 | - if ( nameParts[ 1 ] === '[form' || nameParts[ 1 ] === '[row_ids' ) { | |
| 74 | + if ( nameParts[1] === '[form' || nameParts[1] === '[row_ids' ) { | |
| 83 | 75 | return 0; |
| 84 | 76 | } |
| 85 | 77 | |
| 86 | 78 | // Check if 'this' is in a repeating section |
| 87 | - if ( document.querySelector( 'input[name="item_meta[' + fieldId + '][form]"]' ) ) { | |
| 79 | + if ( jQuery( 'input[name="item_meta[' + fieldId + '][form]"]' ).length ) { | |
| 80 | + | |
| 88 | 81 | // this is a repeatable section with name: item_meta[repeating-section-id][row-id][field-id] |
| 89 | - fieldId = nameParts[ 2 ].replace( '[', '' ); | |
| 82 | + fieldId = nameParts[2].replace( '[', '' ); | |
| 90 | 83 | isRepeating = true; |
| 91 | 84 | } |
| 92 | 85 | |
| 93 | 86 | // Check if 'this' is an other text field and get field ID for it |
| @@ -93,21 +86,21 @@ | ||
| 93 | 86 | // Check if 'this' is an other text field and get field ID for it |
| 94 | 87 | if ( 'other' === fieldId ) { |
| 95 | 88 | if ( isRepeating ) { |
| 96 | 89 | // name for other fields: item_meta[370][0][other][414] |
| 97 | - fieldId = nameParts[ 3 ].replace( '[', '' ); | |
| 90 | + fieldId = nameParts[3].replace( '[', '' ); | |
| 98 | 91 | } else { |
| 99 | 92 | // Other field name: item_meta[other][370] |
| 100 | - fieldId = nameParts[ 1 ].replace( '[', '' ); | |
| 93 | + fieldId = nameParts[1].replace( '[', '' ); | |
| 101 | 94 | } |
| 102 | 95 | } |
| 103 | 96 | |
| 104 | 97 | if ( fullID === true ) { |
| 105 | 98 | // For use in the container div id |
| 106 | - if ( fieldId === nameParts[ 0 ] ) { | |
| 107 | - fieldId = fieldId + '-' + nameParts[ 1 ].replace( '[', '' ); | |
| 99 | + if ( fieldId === nameParts[0]) { | |
| 100 | + fieldId = fieldId + '-' + nameParts[1].replace( '[', '' ); | |
| 108 | 101 | } else { |
| 109 | - fieldId = fieldId + '-' + nameParts[ 0 ] + '-' + nameParts[ 1 ].replace( '[', '' ); | |
| 102 | + fieldId = fieldId + '-' + nameParts[0] + '-' + nameParts[1].replace( '[', '' ); | |
| 110 | 103 | } |
| 111 | 104 | } |
| 112 | 105 | |
| 113 | 106 | return fieldId; |
| @@ -117,18 +110,12 @@ | ||
| 117 | 110 | * Disable the submit button for a given jQuery form object |
| 118 | 111 | * |
| 119 | 112 | * @since 2.03.02 |
| 120 | 113 | * |
| 121 | - * @param {Object} $form | |
| 122 | - */ | |
| 114 | + * @param {object} $form | |
| 115 | + */ | |
| 123 | 116 | 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 | - ); | |
| 117 | + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).attr( 'disabled', 'disabled' ); | |
| 131 | 118 | } |
| 132 | 119 | |
| 133 | 120 | /** |
| 134 | 121 | * Enable the submit button for a given jQuery form object |
| @@ -134,16 +121,12 @@ | ||
| 134 | 121 | * Enable the submit button for a given jQuery form object |
| 135 | 122 | * |
| 136 | 123 | * @since 2.03.02 |
| 137 | 124 | * |
| 138 | - * @param {HTMLElement} form | |
| 139 | - * | |
| 140 | - * @return {void} | |
| 141 | - */ | |
| 142 | - function enableSubmitButton( form ) { | |
| 143 | - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"]' ).forEach( | |
| 144 | - button => button.disabled = false | |
| 145 | - ); | |
| 125 | + * @param {object} $form | |
| 126 | + */ | |
| 127 | + function enableSubmitButton( $form ) { | |
| 128 | + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false ); | |
| 146 | 129 | } |
| 147 | 130 | |
| 148 | 131 | /** |
| 149 | 132 | * Disable the save draft link for a given jQuery form object |
| @@ -149,239 +132,133 @@ | ||
| 149 | 132 | * Disable the save draft link for a given jQuery form object |
| 150 | 133 | * |
| 151 | 134 | * @since 4.04.03 |
| 152 | 135 | * |
| 153 | - * @param {Object} $form | |
| 136 | + * @param {object} $form | |
| 154 | 137 | */ |
| 155 | 138 | 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 | - ); | |
| 139 | + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', 'none' ); | |
| 163 | 140 | } |
| 164 | 141 | |
| 165 | 142 | /** |
| 166 | - * Enable the save draft link for a given form object. | |
| 143 | + * Enable the save draft link for a given jQuery form object | |
| 167 | 144 | * |
| 168 | 145 | * @since 4.04.03 |
| 169 | 146 | * |
| 170 | - * @param {jQuery|HTMLElement} $form | |
| 147 | + * @param {object} $form | |
| 171 | 148 | */ |
| 172 | 149 | function enableSaveDraft( $form ) { |
| 173 | - const form = $form instanceof jQuery ? $form.get( 0 ) : $form; | |
| 174 | - if ( ! form ) { | |
| 175 | - return; | |
| 176 | - } | |
| 177 | - form.querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => { | |
| 178 | - saveDraftButton.disabled = false; | |
| 179 | - saveDraftButton.style.pointerEvents = ''; | |
| 180 | - } ); | |
| 150 | + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', '' ); | |
| 181 | 151 | } |
| 182 | 152 | |
| 183 | - /** | |
| 184 | - * Validate form with JS. | |
| 185 | - * | |
| 186 | - * @param {HTMLElement|jQuery} object | |
| 187 | - * @return {Array} Errors. | |
| 188 | - */ | |
| 189 | 153 | function validateForm( object ) { |
| 190 | - let errors = []; | |
| 154 | + var r, rl, n, nl, fields, field, value, requiredFields, | |
| 155 | + errors = []; | |
| 191 | 156 | |
| 192 | - const vanillaJsObject = 'function' === typeof object.get ? object.get( 0 ) : object; | |
| 193 | - | |
| 194 | - // Required field validation. | |
| 195 | - vanillaJsObject?.querySelectorAll( '.frm_required_field' ).forEach( | |
| 196 | - requiredField => { | |
| 197 | - const isVisible = requiredField.offsetParent !== null; | |
| 198 | - if ( ! isVisible ) { | |
| 199 | - return; | |
| 157 | + // Make sure required text field is filled in | |
| 158 | + requiredFields = jQuery( object ).find( | |
| 159 | + '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea' | |
| 160 | + ).filter( ':not(.frm_optional)' ); | |
| 161 | + if ( requiredFields.length ) { | |
| 162 | + for ( r = 0, rl = requiredFields.length; r < rl; r++ ) { | |
| 163 | + if ( hasClass( requiredFields[r], 'ed_button' ) ) { | |
| 164 | + // skip rich text field buttons. | |
| 165 | + continue; | |
| 200 | 166 | } |
| 201 | - | |
| 202 | - requiredField.querySelectorAll( 'input, select, textarea' ).forEach( | |
| 203 | - requiredInput => { | |
| 204 | - if ( hasClass( requiredInput, 'frm_optional' ) || hasClass( requiredInput, 'ed_button' ) ) { | |
| 205 | - // skip rich text field buttons. | |
| 206 | - return; | |
| 207 | - } | |
| 208 | - | |
| 209 | - errors = checkRequiredField( requiredInput, errors ); | |
| 210 | - } | |
| 211 | - ); | |
| 167 | + errors = checkRequiredField( requiredFields[r], errors ); | |
| 212 | 168 | } |
| 213 | - ); | |
| 169 | + } | |
| 214 | 170 | |
| 215 | - vanillaJsObject?.querySelectorAll( 'input,select,textarea' ).forEach( | |
| 216 | - field => { | |
| 217 | - if ( '' === field.value ) { | |
| 218 | - if ( 'number' === field.type ) { | |
| 219 | - // A number field will return an empty string when it is invalid. | |
| 220 | - checkValidity( field, errors ); | |
| 171 | + fields = jQuery( object ).find( 'input,select,textarea' ); | |
| 172 | + if ( fields.length ) { | |
| 173 | + for ( n = 0, nl = fields.length; n < nl; n++ ) { | |
| 174 | + field = fields[n]; | |
| 175 | + value = field.value; | |
| 176 | + if ( value !== '' ) { | |
| 177 | + if ( field.type === 'hidden' ) { | |
| 178 | + // don't validate | |
| 179 | + } else if ( field.type === 'number' ) { | |
| 180 | + errors = checkNumberField( field, errors ); | |
| 181 | + } else if ( field.type === 'email' ) { | |
| 182 | + errors = checkEmailField( field, errors ); | |
| 183 | + } else if ( field.type === 'password' ) { | |
| 184 | + errors = checkPasswordField( field, errors ); | |
| 185 | + } else if ( field.type === 'url' ) { | |
| 186 | + errors = checkUrlField( field, errors ); | |
| 187 | + } else if ( field.pattern !== null ) { | |
| 188 | + errors = checkPatternField( field, errors ); | |
| 221 | 189 | } |
| 222 | - | |
| 223 | - const isConfirmationField = field.name && 0 === field.name.indexOf( 'item_meta[conf_' ); | |
| 224 | - if ( ! isConfirmationField ) { | |
| 225 | - // Allow a blank confirmation field to still call validateFieldValue. | |
| 226 | - // If we continue for a confirmation field there are issues with forms submitting with a blank confirmation field. | |
| 227 | - return; | |
| 228 | - } | |
| 229 | 190 | } |
| 230 | - | |
| 231 | - validateFieldValue( field, errors, true ); | |
| 232 | - checkValidity( field, errors ); | |
| 233 | 191 | } |
| 234 | - ); | |
| 192 | + } | |
| 235 | 193 | |
| 236 | - // Invisible captchas are processed after validation. | |
| 237 | - // We only want to validate a visible captcha on submit. | |
| 238 | - if ( ! hasInvisibleRecaptcha( object ) ) { | |
| 239 | - errors = validateRecaptcha( object, errors ); | |
| 240 | - } | |
| 194 | + errors = validateRecaptcha( object, errors ); | |
| 241 | 195 | |
| 242 | 196 | return errors; |
| 243 | 197 | } |
| 244 | 198 | |
| 245 | 199 | /** |
| 246 | - * Check the ValidityState interface for the field. | |
| 247 | - * If it is invalid, show an error for it. | |
| 248 | - * | |
| 249 | - * @param {HTMLElement} field | |
| 250 | - * @param {Array} errors | |
| 251 | - * @return {void} | |
| 252 | - */ | |
| 253 | - function checkValidity( field, errors ) { | |
| 254 | - let fieldID; | |
| 255 | - if ( 'object' !== typeof field.validity || false !== field.validity.valid ) { | |
| 256 | - return; | |
| 257 | - } | |
| 258 | - | |
| 259 | - fieldID = getFieldId( field, true ); | |
| 260 | - if ( 'undefined' === typeof errors[ fieldID ] ) { | |
| 261 | - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); | |
| 262 | - } | |
| 263 | - | |
| 264 | - if ( 'function' === typeof field.reportValidity ) { | |
| 265 | - // This triggers an error pop up. | |
| 266 | - field.reportValidity(); | |
| 267 | - } | |
| 268 | - } | |
| 269 | - | |
| 270 | - /** | |
| 271 | 200 | * @since 5.0.10 |
| 272 | 201 | * |
| 273 | - * @param {Object} element | |
| 202 | + * @param {object} element | |
| 274 | 203 | * @param {string} targetClass |
| 275 | - * @return {boolean} True if the element has the target class. | |
| 204 | + * @returns {boolean} | |
| 276 | 205 | */ |
| 277 | 206 | function hasClass( element, targetClass ) { |
| 278 | - return element.classList && element.classList.contains( targetClass ); | |
| 207 | + var className = ' ' + element.className + ' '; | |
| 208 | + return -1 !== className.indexOf( ' ' + targetClass + ' ' ); | |
| 279 | 209 | } |
| 280 | 210 | |
| 281 | - /** | |
| 282 | - * @param {HTMLElement} field | |
| 283 | - */ | |
| 284 | 211 | function maybeValidateChange( field ) { |
| 285 | 212 | if ( field.type === 'url' ) { |
| 286 | - maybeAddHttpsToUrl( field ); | |
| 213 | + maybeAddHttpToUrl( field ); | |
| 287 | 214 | } |
| 288 | - const form = field.closest( 'form' ); | |
| 289 | - if ( form && hasClass( form, 'frm_js_validate' ) ) { | |
| 215 | + if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) { | |
| 290 | 216 | validateField( field ); |
| 291 | 217 | } |
| 292 | 218 | } |
| 293 | 219 | |
| 294 | - /** | |
| 295 | - * @param {HTMLElement} field | |
| 296 | - */ | |
| 297 | - function maybeAddHttpsToUrl( field ) { | |
| 298 | - const url = field.value; | |
| 299 | - const matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ ); | |
| 220 | + function maybeAddHttpToUrl( field ) { | |
| 221 | + var url = field.value; | |
| 222 | + var matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ ); | |
| 300 | 223 | if ( field.value !== '' && matches === null ) { |
| 301 | - field.value = 'https://' + url; | |
| 224 | + field.value = 'http://' + url; | |
| 302 | 225 | } |
| 303 | 226 | } |
| 304 | 227 | |
| 305 | - /** | |
| 306 | - * Validate a field with JS. | |
| 307 | - * | |
| 308 | - * @param {HTMLElement} field | |
| 309 | - * | |
| 310 | - * @return {void} | |
| 311 | - */ | |
| 312 | 228 | function validateField( field ) { |
| 313 | - let errors, key; | |
| 229 | + var key, | |
| 230 | + errors = [], | |
| 231 | + $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 314 | 232 | |
| 315 | - errors = []; | |
| 316 | - const fieldContainer = field.closest( '.frm_form_field' ); | |
| 317 | - | |
| 318 | - if ( ! fieldContainer ) { | |
| 319 | - // Hidden fields do not have a field container and do not require JS validation. | |
| 320 | - return; | |
| 321 | - } | |
| 322 | - | |
| 323 | - if ( hasClass( fieldContainer, 'frm_required_field' ) && ! hasClass( field, 'frm_optional' ) ) { | |
| 233 | + if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) { | |
| 324 | 234 | errors = checkRequiredField( field, errors ); |
| 325 | 235 | } |
| 326 | 236 | |
| 327 | 237 | if ( errors.length < 1 ) { |
| 328 | - validateFieldValue( field, errors, false ); | |
| 238 | + if ( field.type === 'email' ) { | |
| 239 | + errors = checkEmailField( field, errors ); | |
| 240 | + } else if ( field.type === 'password' ) { | |
| 241 | + errors = checkPasswordField( field, errors ); | |
| 242 | + } else if ( field.type === 'number' ) { | |
| 243 | + errors = checkNumberField( field, errors ); | |
| 244 | + } else if ( field.type === 'url' ) { | |
| 245 | + errors = checkUrlField( field, errors ); | |
| 246 | + } else if ( field.pattern !== null ) { | |
| 247 | + errors = checkPatternField( field, errors ); | |
| 248 | + } | |
| 329 | 249 | } |
| 330 | 250 | |
| 331 | - removeFieldError( fieldContainer ); | |
| 332 | - if ( Object.keys( errors ).length > 0 ) { | |
| 251 | + removeFieldError( $fieldCont ); | |
| 252 | + if ( Object.keys( errors ).length > 0 ) { | |
| 333 | 253 | for ( key in errors ) { |
| 334 | - addFieldError( fieldContainer, key, errors ); | |
| 254 | + addFieldError( $fieldCont, key, errors ); | |
| 335 | 255 | } |
| 336 | 256 | } |
| 337 | 257 | } |
| 338 | 258 | |
| 339 | - /** | |
| 340 | - * Validates a field value. | |
| 341 | - * | |
| 342 | - * @since 6.15 Added `onSubmit` parameter. | |
| 343 | - * | |
| 344 | - * @param {HTMLElement} field Field input. | |
| 345 | - * @param {Object} errors Errors data. | |
| 346 | - * @param {boolean} onSubmit Is `true` if the form is being submitted. | |
| 347 | - */ | |
| 348 | - function validateFieldValue( field, errors, onSubmit ) { | |
| 349 | - if ( field.type === 'hidden' ) { | |
| 350 | - // don't validate | |
| 351 | - } else if ( field.type === 'number' ) { | |
| 352 | - checkNumberField( field, errors ); | |
| 353 | - } else if ( field.type === 'email' ) { | |
| 354 | - checkEmailField( field, errors, onSubmit ); | |
| 355 | - } else if ( field.type === 'password' ) { | |
| 356 | - checkPasswordField( field, errors, onSubmit ); | |
| 357 | - } else if ( field.type === 'url' ) { | |
| 358 | - checkUrlField( field, errors ); | |
| 359 | - } else if ( field.pattern !== null ) { | |
| 360 | - checkPatternField( field, errors ); | |
| 361 | - } | |
| 362 | - | |
| 363 | - if ( 'tel' === field.type && shouldCheckConfirmField( field, onSubmit ) ) { | |
| 364 | - confirmField( field, errors ); | |
| 365 | - } | |
| 366 | - | |
| 367 | - /** | |
| 368 | - * @since 6.15 Added `onSubmit` to the data. | |
| 369 | - */ | |
| 370 | - triggerCustomEvent( document, 'frm_validate_field_value', { | |
| 371 | - field: field, | |
| 372 | - errors: errors, | |
| 373 | - onSubmit: onSubmit | |
| 374 | - } ); | |
| 375 | - } | |
| 376 | - | |
| 377 | - /** | |
| 378 | - * @param {HTMLElement} field | |
| 379 | - * @param {Array} errors | |
| 380 | - * @return {Array} Errors | |
| 381 | - */ | |
| 382 | 259 | function checkRequiredField( field, errors ) { |
| 383 | - let tempVal, i, placeholder, | |
| 260 | + var checkGroup, tempVal, i, placeholder, | |
| 384 | 261 | val = '', |
| 385 | 262 | fieldID = '', |
| 386 | 263 | fileID = field.getAttribute( 'data-frmfile' ); |
| 387 | 264 | |
| @@ -389,19 +266,12 @@ | ||
| 389 | 266 | return errors; |
| 390 | 267 | } |
| 391 | 268 | |
| 392 | 269 | if ( field.type === 'checkbox' || field.type === 'radio' ) { |
| 393 | - document.querySelectorAll( 'input[name="' + field.name + '"]' ).forEach( function( input ) { | |
| 394 | - const requiredField = input.closest( '.frm_required_field' ); | |
| 395 | - if ( ! requiredField ) { | |
| 396 | - return; | |
| 397 | - } | |
| 398 | - | |
| 399 | - const checkedInputs = requiredField.querySelectorAll( 'input:checked' ); | |
| 400 | - checkedInputs.forEach( function( checkedInput ) { | |
| 401 | - val = checkedInput.value; | |
| 402 | - } ); | |
| 403 | - } ); | |
| 270 | + checkGroup = jQuery( 'input[name="' + field.name + '"]' ).closest( '.frm_required_field' ).find( 'input:checked' ); | |
| 271 | + jQuery( checkGroup ).each( function() { | |
| 272 | + val = this.value; | |
| 273 | + }); | |
| 404 | 274 | } else if ( field.type === 'file' || fileID ) { |
| 405 | 275 | if ( typeof fileID === 'undefined' ) { |
| 406 | 276 | fileID = getFieldId( field, true ); |
| 407 | 277 | fileID = fileID.replace( 'file', '' ); |
| @@ -416,10 +286,9 @@ | ||
| 416 | 286 | // skip hidden other fields |
| 417 | 287 | return errors; |
| 418 | 288 | } |
| 419 | 289 | |
| 420 | - val = jQuery( field ).val(); // eslint-disable-line no-jquery/no-val | |
| 421 | - | |
| 290 | + val = jQuery( field ).val(); | |
| 422 | 291 | if ( val === null ) { |
| 423 | 292 | val = ''; |
| 424 | 293 | } else if ( typeof val !== 'string' ) { |
| 425 | 294 | tempVal = val; |
| @@ -424,10 +293,10 @@ | ||
| 424 | 293 | } else if ( typeof val !== 'string' ) { |
| 425 | 294 | tempVal = val; |
| 426 | 295 | val = ''; |
| 427 | 296 | for ( i = 0; i < tempVal.length; i++ ) { |
| 428 | - if ( tempVal[ i ] !== '' ) { | |
| 429 | - val = tempVal[ i ]; | |
| 297 | + if ( tempVal[i] !== '' ) { | |
| 298 | + val = tempVal[i]; | |
| 430 | 299 | } |
| 431 | 300 | } |
| 432 | 301 | } |
| 433 | 302 | |
| @@ -440,22 +309,14 @@ | ||
| 440 | 309 | } else { |
| 441 | 310 | fieldID = getFieldId( field, true ); |
| 442 | 311 | } |
| 443 | 312 | |
| 444 | - // Make sure fieldID is a string. | |
| 445 | - // fieldID may be a number which doesn't include a .replace function. | |
| 446 | - if ( 'function' !== typeof fieldID.replace ) { | |
| 447 | - fieldID = fieldID.toString(); | |
| 448 | - } | |
| 449 | - | |
| 450 | 313 | if ( hasClass( field, 'frm_time_select' ) ) { |
| 451 | 314 | // set id for time field |
| 452 | 315 | fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' ); |
| 453 | 316 | } else if ( isSignatureField( field ) ) { |
| 454 | 317 | 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 : ''; | |
| 318 | + val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val(); | |
| 458 | 319 | } |
| 459 | 320 | fieldID = fieldID.replace( '-typed', '' ); |
| 460 | 321 | } |
| 461 | 322 | |
| @@ -476,56 +337,35 @@ | ||
| 476 | 337 | |
| 477 | 338 | return errors; |
| 478 | 339 | } |
| 479 | 340 | |
| 480 | - /** | |
| 481 | - * @param {HTMLElement} field | |
| 482 | - * @return {boolean} True if the input is a typed signature input. | |
| 483 | - */ | |
| 484 | 341 | function isSignatureField( field ) { |
| 485 | - const name = field.getAttribute( 'name' ); | |
| 342 | + var name = field.getAttribute( 'name' ); | |
| 486 | 343 | return 'string' === typeof name && '[typed]' === name.substr( -7 ); |
| 487 | 344 | } |
| 488 | 345 | |
| 489 | - /** | |
| 490 | - * @param {HTMLElement} field | |
| 491 | - * @return {boolean} True if the field is a SSA appointment field. | |
| 492 | - */ | |
| 493 | 346 | function isAppointmentField( field ) { |
| 494 | 347 | return hasClass( field, 'ssa_appointment_form_field_appointment_id' ); |
| 495 | 348 | } |
| 496 | 349 | |
| 497 | - /** | |
| 498 | - * @param {HTMLElement} field | |
| 499 | - * @return {boolean} True if the field is inline datepicker field. | |
| 500 | - */ | |
| 501 | 350 | function isInlineDatepickerField( field ) { |
| 502 | 351 | return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' ); |
| 503 | 352 | } |
| 504 | 353 | |
| 505 | - /** | |
| 506 | - * @param {string|number} fileID | |
| 507 | - * @return {string} File input value. | |
| 508 | - */ | |
| 509 | 354 | function getFileVals( fileID ) { |
| 510 | - let val = ''; | |
| 511 | - const fileFields = document.querySelectorAll( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); | |
| 355 | + var val = '', | |
| 356 | + fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); | |
| 512 | 357 | |
| 513 | - fileFields.forEach( function( field ) { | |
| 358 | + fileFields.each( function() { | |
| 514 | 359 | if ( val === '' ) { |
| 515 | - val = field.value; | |
| 360 | + val = this.value; | |
| 516 | 361 | } |
| 517 | - } ); | |
| 362 | + }); | |
| 518 | 363 | return val; |
| 519 | 364 | } |
| 520 | 365 | |
| 521 | - /** | |
| 522 | - * @param {HTMLElement} field | |
| 523 | - * @param {Array} errors | |
| 524 | - * @return {void} | |
| 525 | - */ | |
| 526 | 366 | function checkUrlField( field, errors ) { |
| 527 | - let fieldID, | |
| 367 | + var fieldID, | |
| 528 | 368 | url = field.value; |
| 529 | 369 | |
| 530 | 370 | if ( url !== '' && ! /^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i.test( url ) ) { |
| 531 | 371 | fieldID = getFieldId( field, true ); |
| @@ -532,44 +372,13 @@ | ||
| 532 | 372 | if ( ! ( fieldID in errors ) ) { |
| 533 | 373 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 534 | 374 | } |
| 535 | 375 | } |
| 376 | + return errors; | |
| 536 | 377 | } |
| 537 | 378 | |
| 538 | - /** | |
| 539 | - * Checks if the confirm field should be checked. | |
| 540 | - * | |
| 541 | - * @since 6.15 | |
| 542 | - * | |
| 543 | - * @param {HTMLElement} field Field input. | |
| 544 | - * @param {boolean} onSubmit Is `true` if the form is being submitted. | |
| 545 | - * @return {boolean} True if we should confirm the field. | |
| 546 | - */ | |
| 547 | - function shouldCheckConfirmField( field, onSubmit ) { | |
| 548 | - if ( onSubmit ) { | |
| 549 | - // Always check on submitting. | |
| 550 | - return true; | |
| 551 | - } | |
| 552 | - | |
| 553 | - if ( 0 === field.id.indexOf( 'field_conf_' ) ) { | |
| 554 | - // Always check if it's the confirm field. | |
| 555 | - return true; | |
| 556 | - } | |
| 557 | - | |
| 558 | - return false; | |
| 559 | - } | |
| 560 | - | |
| 561 | - /** | |
| 562 | - * Check the email field for errors. | |
| 563 | - * | |
| 564 | - * @since 6.15 Added `onSubmit` parameter. | |
| 565 | - * | |
| 566 | - * @param {HTMLElement} field Field input. | |
| 567 | - * @param {Object} errors Errors data. | |
| 568 | - * @param {boolean} onSubmit Is `true` if the form is being submitted. | |
| 569 | - */ | |
| 570 | - function checkEmailField( field, errors, onSubmit ) { | |
| 571 | - const fieldID = getFieldId( field, true ), | |
| 379 | + function checkEmailField( field, errors ) { | |
| 380 | + var fieldID = getFieldId( field, true ), | |
| 572 | 381 | pattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i; |
| 573 | 382 | |
| 574 | 383 | // validate the current field we're editing first |
| 575 | 384 | if ( '' !== field.value && pattern.test( field.value ) === false ) { |
| @@ -575,35 +384,19 @@ | ||
| 575 | 384 | if ( '' !== field.value && pattern.test( field.value ) === false ) { |
| 576 | 385 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 577 | 386 | } |
| 578 | 387 | |
| 579 | - if ( shouldCheckConfirmField( field, onSubmit ) ) { | |
| 580 | - confirmField( field, errors ); | |
| 581 | - } | |
| 388 | + confirmField( field, errors ); | |
| 389 | + return errors; | |
| 582 | 390 | } |
| 583 | 391 | |
| 584 | - /** | |
| 585 | - * Check the password field for errors. | |
| 586 | - * | |
| 587 | - * @since 6.15 Added `onSubmit` parameter. | |
| 588 | - * | |
| 589 | - * @param {HTMLElement} field Field input. | |
| 590 | - * @param {Object} errors Errors data. | |
| 591 | - * @param {boolean} onSubmit Is `true` if the form is being submitted. | |
| 592 | - */ | |
| 593 | - function checkPasswordField( field, errors, onSubmit ) { | |
| 594 | - if ( shouldCheckConfirmField( field, onSubmit ) ) { | |
| 595 | - confirmField( field, errors ); | |
| 596 | - } | |
| 392 | + function checkPasswordField( field, errors ) { | |
| 393 | + confirmField( field, errors ); | |
| 394 | + return errors; | |
| 597 | 395 | } |
| 598 | 396 | |
| 599 | - /** | |
| 600 | - * @param {HTMLElement} field | |
| 601 | - * @param {Array} errors | |
| 602 | - * @return {void} | |
| 603 | - */ | |
| 604 | 397 | function confirmField( field, errors ) { |
| 605 | - let value, confirmValue, firstField, | |
| 398 | + var value, confirmValue, firstField, | |
| 606 | 399 | fieldID = getFieldId( field, true ), |
| 607 | 400 | strippedId = field.id.replace( 'conf_', '' ), |
| 608 | 401 | strippedFieldID = fieldID.replace( 'conf_', '' ), |
| 609 | 402 | confirmField = document.getElementById( strippedId.replace( 'field_', 'field_conf_' ) ); |
| @@ -615,9 +408,9 @@ | ||
| 615 | 408 | if ( fieldID !== strippedFieldID ) { |
| 616 | 409 | firstField = document.getElementById( strippedId ); |
| 617 | 410 | value = firstField.value; |
| 618 | 411 | confirmValue = confirmField.value; |
| 619 | - if ( value !== confirmValue ) { | |
| 412 | + if ( '' !== value && '' !== confirmValue && value !== confirmValue ) { | |
| 620 | 413 | errors[ 'conf_' + strippedFieldID ] = getFieldValidationMessage( confirmField, 'data-confmsg' ); |
| 621 | 414 | } |
| 622 | 415 | } else { |
| 623 | 416 | validateField( confirmField ); |
| @@ -623,15 +416,10 @@ | ||
| 623 | 416 | validateField( confirmField ); |
| 624 | 417 | } |
| 625 | 418 | } |
| 626 | 419 | |
| 627 | - /** | |
| 628 | - * @param {HTMLElement} field | |
| 629 | - * @param {Array} errors | |
| 630 | - * @return {void} | |
| 631 | - */ | |
| 632 | 420 | function checkNumberField( field, errors ) { |
| 633 | - let fieldID, | |
| 421 | + var fieldID, | |
| 634 | 422 | number = field.value; |
| 635 | 423 | |
| 636 | 424 | if ( number !== '' && isNaN( number / 1 ) !== false ) { |
| 637 | 425 | fieldID = getFieldId( field, true ); |
| @@ -638,17 +426,13 @@ | ||
| 638 | 426 | if ( ! ( fieldID in errors ) ) { |
| 639 | 427 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 640 | 428 | } |
| 641 | 429 | } |
| 430 | + return errors; | |
| 642 | 431 | } |
| 643 | 432 | |
| 644 | - /** | |
| 645 | - * @param {HTMLElement} field | |
| 646 | - * @param {Array} errors | |
| 647 | - * @return {void} | |
| 648 | - */ | |
| 649 | 433 | function checkPatternField( field, errors ) { |
| 650 | - let fieldID, | |
| 434 | + var fieldID, | |
| 651 | 435 | text = field.value, |
| 652 | 436 | format = getFieldValidationMessage( field, 'pattern' ); |
| 653 | 437 | |
| 654 | 438 | if ( format !== '' && text !== '' ) { |
| @@ -653,187 +437,95 @@ | ||
| 653 | 437 | |
| 654 | 438 | if ( format !== '' && text !== '' ) { |
| 655 | 439 | fieldID = getFieldId( field, true ); |
| 656 | 440 | if ( ! ( fieldID in errors ) ) { |
| 657 | - if ( 'object' === typeof window.frmProForm && 'function' === typeof window.frmProForm.isIntlPhoneInput && window.frmProForm.isIntlPhoneInput( field ) ) { | |
| 658 | - if ( ! window.frmProForm.validateIntlPhoneInput( field ) ) { | |
| 659 | - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); | |
| 660 | - } | |
| 661 | - } else { | |
| 662 | - format = new RegExp( '^' + format + '$', 'i' ); | |
| 663 | - if ( format.test( text ) === false ) { | |
| 664 | - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); | |
| 665 | - } | |
| 441 | + format = new RegExp( '^' + format + '$', 'i' ); | |
| 442 | + if ( format.test( text ) === false ) { | |
| 443 | + errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); | |
| 666 | 444 | } |
| 667 | 445 | } |
| 668 | 446 | } |
| 447 | + return errors; | |
| 669 | 448 | } |
| 670 | 449 | |
| 671 | - /** | |
| 672 | - * Set color for select placeholders. | |
| 673 | - * | |
| 674 | - * @since 6.5.1 | |
| 675 | - */ | |
| 676 | - function setSelectPlaceholderColor() { | |
| 677 | - let selects = document.querySelectorAll( '.form-field select' ), | |
| 678 | - styleElement = document.querySelector( '.with_frm_style' ), | |
| 679 | - textColorDisabled = styleElement ? getComputedStyle( styleElement ).getPropertyValue( '--text-color-disabled' ).trim() : '', | |
| 680 | - changeSelectColor; | |
| 450 | + function hasInvisibleRecaptcha( object ) { | |
| 451 | + var recaptcha, recaptchaID, alreadyChecked; | |
| 681 | 452 | |
| 682 | - // Exit if there are no select elements or the textColorDisabled property is missing | |
| 683 | - if ( ! selects.length || ! textColorDisabled ) { | |
| 684 | - return; | |
| 685 | - } | |
| 686 | - | |
| 687 | - // Function to change the color of a select element | |
| 688 | - changeSelectColor = function( select ) { | |
| 689 | - if ( select.options[ select.selectedIndex ] && hasClass( select.options[ select.selectedIndex ], 'frm-select-placeholder' ) ) { | |
| 690 | - select.style.setProperty( 'color', textColorDisabled, 'important' ); | |
| 691 | - } else { | |
| 692 | - select.style.color = ''; | |
| 693 | - } | |
| 694 | - }; | |
| 695 | - | |
| 696 | - // Use a loop to iterate through each select element | |
| 697 | - Array.prototype.forEach.call( selects, function( select ) { | |
| 698 | - // Apply the color change to each select element | |
| 699 | - changeSelectColor( select ); | |
| 700 | - | |
| 701 | - // Add an event listener for future changes | |
| 702 | - select.addEventListener( 'change', function() { | |
| 703 | - changeSelectColor( select ); | |
| 704 | - } ); | |
| 705 | - } ); | |
| 706 | - } | |
| 707 | - | |
| 708 | - /** | |
| 709 | - * @param {HTMLElement|jQuery} object | |
| 710 | - * | |
| 711 | - * @return {HTMLElement|false} Captcha element if there is an invisible recaptcha. | |
| 712 | - */ | |
| 713 | - function hasInvisibleRecaptcha( object ) { | |
| 714 | 453 | if ( isGoingToPrevPage( object ) ) { |
| 715 | 454 | return false; |
| 716 | 455 | } |
| 717 | 456 | |
| 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 ); | |
| 457 | + recaptcha = jQuery( object ).find( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' ); | |
| 458 | + if ( recaptcha.length ) { | |
| 459 | + recaptchaID = recaptcha.data( 'rid' ); | |
| 460 | + alreadyChecked = grecaptcha.getResponse( recaptchaID ); | |
| 727 | 461 | if ( alreadyChecked.length === 0 ) { |
| 728 | 462 | return recaptcha; |
| 463 | + } else { | |
| 464 | + return false; | |
| 729 | 465 | } |
| 466 | + } else { | |
| 467 | + return false; | |
| 730 | 468 | } |
| 731 | - | |
| 732 | - return false; | |
| 733 | 469 | } |
| 734 | 470 | |
| 735 | - /** | |
| 736 | - * @param {HTMLElement} invisibleRecaptcha | |
| 737 | - * | |
| 738 | - * @return {void} | |
| 739 | - */ | |
| 740 | 471 | function executeInvisibleRecaptcha( invisibleRecaptcha ) { |
| 741 | - const recaptchaID = invisibleRecaptcha.dataset.rid; | |
| 472 | + var recaptchaID = invisibleRecaptcha.data( 'rid' ); | |
| 742 | 473 | grecaptcha.reset( recaptchaID ); |
| 743 | 474 | grecaptcha.execute( recaptchaID ); |
| 744 | 475 | } |
| 745 | 476 | |
| 746 | 477 | function validateRecaptcha( form, errors ) { |
| 747 | - const formEl = form instanceof jQuery ? form.get( 0 ) : form; | |
| 748 | - if ( ! formEl ) { | |
| 749 | - return errors; | |
| 750 | - } | |
| 478 | + var recaptchaID, response, fieldContainer, fieldID, | |
| 479 | + $recaptcha = jQuery( form ).find( '.frm-g-recaptcha' ); | |
| 480 | + if ( $recaptcha.length ) { | |
| 481 | + recaptchaID = $recaptcha.data( 'rid' ); | |
| 751 | 482 | |
| 752 | - const recaptcha = formEl.querySelector( '.frm-g-recaptcha' ); | |
| 753 | - if ( ! recaptcha ) { | |
| 754 | - return errors; | |
| 755 | - } | |
| 756 | - | |
| 757 | - const recaptchaID = recaptcha.dataset.rid; | |
| 758 | - let response; | |
| 759 | - | |
| 760 | - try { | |
| 761 | - response = grecaptcha.getResponse( recaptchaID ); | |
| 762 | - } catch ( e ) { | |
| 763 | - if ( formEl.querySelector( 'input[name="recaptcha_checked"]' ) ) { | |
| 764 | - return errors; | |
| 483 | + try { | |
| 484 | + response = grecaptcha.getResponse( recaptchaID ); | |
| 485 | + } catch ( e ) { | |
| 486 | + if ( jQuery( form ).find( 'input[name="recaptcha_checked"]' ).length ) { | |
| 487 | + return errors; | |
| 488 | + } else { | |
| 489 | + response = ''; | |
| 490 | + } | |
| 765 | 491 | } |
| 766 | - response = ''; | |
| 767 | - } | |
| 768 | 492 | |
| 769 | - 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', '' ); | |
| 493 | + if ( response.length === 0 ) { | |
| 494 | + fieldContainer = $recaptcha.closest( '.frm_form_field' ); | |
| 495 | + fieldID = fieldContainer.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_container', '' ); | |
| 773 | 496 | errors[ fieldID ] = ''; |
| 774 | 497 | } |
| 775 | 498 | } |
| 776 | - | |
| 777 | 499 | return errors; |
| 778 | 500 | } |
| 779 | 501 | |
| 780 | - /** | |
| 781 | - * @param {HTMLElement} field | |
| 782 | - * @param {string} messageType | |
| 783 | - * @return {string} The error message to display. | |
| 784 | - */ | |
| 785 | 502 | function getFieldValidationMessage( field, messageType ) { |
| 786 | - let msg = field.getAttribute( messageType ); | |
| 503 | + var msg, errorHtml; | |
| 504 | + | |
| 505 | + msg = field.getAttribute( messageType ); | |
| 787 | 506 | if ( null === msg ) { |
| 788 | 507 | msg = ''; |
| 789 | 508 | } |
| 790 | 509 | |
| 791 | 510 | if ( '' !== msg && shouldWrapErrorHtmlAroundMessageType( messageType ) ) { |
| 792 | - msg = wrapErrorHtml( msg, field ); | |
| 511 | + errorHtml = field.getAttribute( 'data-error-html' ); | |
| 512 | + if ( null !== errorHtml ) { | |
| 513 | + errorHtml = errorHtml.replace( /\+/g, '%20' ); | |
| 514 | + msg = decodeURIComponent( errorHtml ).replace( '[error]', msg ); | |
| 515 | + msg = msg.replace( '[key]', getFieldId( field, false ) ); | |
| 516 | + } | |
| 793 | 517 | } |
| 794 | 518 | |
| 795 | 519 | return msg; |
| 796 | 520 | } |
| 797 | 521 | |
| 798 | - /** | |
| 799 | - * @param {string} msg | |
| 800 | - * @param {HTMLElement} field | |
| 801 | - * @return {string} The error HTML to use. | |
| 802 | - */ | |
| 803 | - function wrapErrorHtml( msg, field ) { | |
| 804 | - let errorHtml = field.getAttribute( 'data-error-html' ); | |
| 805 | - if ( null === errorHtml ) { | |
| 806 | - return msg; | |
| 807 | - } | |
| 808 | - | |
| 809 | - errorHtml = errorHtml.replace( /\+/g, '%20' ); | |
| 810 | - msg = decodeURIComponent( errorHtml ).replace( '[error]', msg ); | |
| 811 | - const fieldId = getFieldId( field, false ); | |
| 812 | - const split = fieldId.split( '-' ); | |
| 813 | - const fieldIdParts = field.id.split( '_' ); | |
| 814 | - fieldIdParts.shift(); // Drop the "field" value from the front. | |
| 815 | - split[ 0 ] = fieldIdParts.join( '_' ); | |
| 816 | - const errorKey = split.join( '-' ); | |
| 817 | - return msg.replace( '[key]', errorKey ); | |
| 818 | - } | |
| 819 | - | |
| 820 | 522 | function shouldWrapErrorHtmlAroundMessageType( type ) { |
| 821 | 523 | return 'pattern' !== type; |
| 822 | 524 | } |
| 823 | 525 | |
| 824 | - /** | |
| 825 | - * Check if JS validation should happen. | |
| 826 | - * | |
| 827 | - * @param {HTMLElement|Object} object Form object. | |
| 828 | - * @return {boolean} True if validation is enabled and we are not saving a draft or going to a previous page. | |
| 829 | - */ | |
| 830 | 526 | function shouldJSValidate( object ) { |
| 831 | - if ( 'function' === typeof object.get ) { | |
| 832 | - // Get the HTMLElement from a jQuery object. | |
| 833 | - object = object.get( 0 ); | |
| 834 | - } | |
| 835 | - let validate = hasClass( object, 'frm_js_validate' ); | |
| 527 | + var validate = jQuery( object ).hasClass( 'frm_js_validate' ); | |
| 836 | 528 | if ( validate && typeof frmProForm !== 'undefined' && ( frmProForm.savingDraft( object ) || frmProForm.goingToPreviousPage( object ) ) ) { |
| 837 | 529 | validate = false; |
| 838 | 530 | } |
| 839 | 531 | |
| @@ -839,98 +531,54 @@ | ||
| 839 | 531 | |
| 840 | 532 | return validate; |
| 841 | 533 | } |
| 842 | 534 | |
| 843 | - /** | |
| 844 | - * @param {HTMLElement} object | |
| 845 | - * @param {string} action | |
| 846 | - * @return {void} | |
| 847 | - */ | |
| 848 | 535 | function getFormErrors( object, action ) { |
| 849 | - let data, success, error, shouldTriggerEvent; | |
| 536 | + var fieldset, data, success, error; | |
| 850 | 537 | |
| 851 | - const fieldsets = object.querySelectorAll( '.frm_form_field' ); | |
| 852 | - fieldsets.forEach( field => field.classList.add( 'frm_doing_ajax' ) ); | |
| 538 | + if ( typeof action === 'undefined' ) { | |
| 539 | + jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 540 | + } | |
| 853 | 541 | |
| 854 | - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line no-jquery/no-serialize, camelcase | |
| 855 | - shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' ); | |
| 542 | + fieldset = jQuery( object ).find( '.frm_form_field' ); | |
| 543 | + fieldset.addClass( 'frm_doing_ajax' ); | |
| 856 | 544 | |
| 857 | - const doRedirect = response => { | |
| 858 | - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ] ); | |
| 545 | + data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; | |
| 859 | 546 | |
| 860 | - if ( ! response.openInNewTab ) { | |
| 861 | - // We return here because we're redirecting there is no need to update content. | |
| 862 | - window.location = response.redirect; | |
| 863 | - return; | |
| 864 | - } | |
| 865 | - | |
| 866 | - // We don't return here because we're opening in a new tab, the old tab will still update. | |
| 867 | - const newTab = window.open( response.redirect, '_blank' ); | |
| 868 | - if ( ! newTab && response.fallbackMsg && response.content ) { | |
| 869 | - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' ); | |
| 870 | - } | |
| 871 | - }; | |
| 872 | - | |
| 873 | 547 | success = function( response ) { |
| 874 | - let defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay, | |
| 875 | - $fieldCont, key, inCollapsedSection, frmTrigger; | |
| 876 | - | |
| 877 | - defaultResponse = { | |
| 878 | - content: '', | |
| 879 | - errors: {}, | |
| 880 | - pass: false | |
| 881 | - }; | |
| 882 | - | |
| 548 | + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay, | |
| 549 | + $fieldCont, key, inCollapsedSection, frmTrigger, | |
| 550 | + defaultResponse = { 'content': '', 'errors': {}, 'pass': false }; | |
| 883 | 551 | if ( response === null ) { |
| 884 | 552 | response = defaultResponse; |
| 553 | + } | |
| 554 | + | |
| 555 | + response = response.replace( /^\s+|\s+$/g, '' ); | |
| 556 | + if ( response.indexOf( '{' ) === 0 ) { | |
| 557 | + response = JSON.parse( response ); | |
| 885 | 558 | } else { |
| 886 | - // Response is a string. Convert it to an object. | |
| 887 | - response = response.replace( /^\s+|\s+$/g, '' ); | |
| 888 | - if ( response.indexOf( '{' ) === 0 ) { | |
| 889 | - response = JSON.parse( response ); | |
| 890 | - } else { | |
| 891 | - response = defaultResponse; | |
| 892 | - } | |
| 559 | + response = defaultResponse; | |
| 893 | 560 | } |
| 894 | 561 | |
| 895 | 562 | if ( typeof response.redirect !== 'undefined' ) { |
| 896 | - if ( shouldTriggerEvent ) { | |
| 897 | - triggerCustomEvent( object, 'frmSubmitEvent' ); | |
| 898 | - return; | |
| 899 | - } | |
| 900 | - | |
| 901 | - if ( response.delay ) { | |
| 902 | - setTimeout( function() { | |
| 903 | - doRedirect( response ); | |
| 904 | - }, 1000 * response.delay ); | |
| 905 | - } else { | |
| 906 | - doRedirect( response ); | |
| 907 | - } | |
| 908 | - } | |
| 909 | - | |
| 910 | - if ( 'string' === typeof response.content && response.content !== '' ) { | |
| 563 | + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]); | |
| 564 | + window.location = response.redirect; | |
| 565 | + } else if ( response.content !== '' ) { | |
| 911 | 566 | // the form or success message was returned |
| 912 | 567 | |
| 913 | - if ( shouldTriggerEvent ) { | |
| 914 | - triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content } ); | |
| 915 | - return; | |
| 916 | - } | |
| 917 | - | |
| 918 | 568 | removeSubmitLoading( jQuery( object ) ); |
| 919 | - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase | |
| 569 | + if ( frm_js.offset != -1 ) { | |
| 920 | 570 | frmFrontForm.scrollMsg( jQuery( object ), false ); |
| 921 | 571 | } |
| 922 | - | |
| 923 | - const formIdInput = object.querySelector( 'input[name="form_id"]' ); | |
| 924 | - formID = formIdInput ? formIdInput.value : ''; | |
| 572 | + formID = jQuery( object ).find( 'input[name="form_id"]' ).val(); | |
| 925 | 573 | 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 | |
| 574 | + replaceContent = jQuery( object ).closest( '.frm_forms' ); | |
| 927 | 575 | removeAddedScripts( replaceContent, formID ); |
| 928 | 576 | delay = maybeSlideOut( replaceContent, response.content ); |
| 929 | 577 | |
| 930 | 578 | setTimeout( |
| 931 | 579 | function() { |
| 932 | - afterFormSubmittedBeforeReplace( object, response ); | |
| 580 | + var container, input, previousInput; | |
| 933 | 581 | |
| 934 | 582 | replaceContent.replaceWith( response.content ); |
| 935 | 583 | |
| 936 | 584 | addUrlParam( response ); |
| @@ -935,17 +583,25 @@ | ||
| 935 | 583 | |
| 936 | 584 | addUrlParam( response ); |
| 937 | 585 | |
| 938 | 586 | 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 : ''; | |
| 587 | + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val(); | |
| 588 | + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val(); | |
| 945 | 589 | frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object ); |
| 946 | 590 | } |
| 947 | 591 | |
| 592 | + if ( typeof response.recaptcha !== 'undefined' ) { | |
| 593 | + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' ); | |
| 594 | + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">'; | |
| 595 | + previousInput = container.find( 'input[name="recaptcha_checked"]' ); | |
| 596 | + | |
| 597 | + if ( previousInput.length ) { | |
| 598 | + previousInput.replaceWith( input ); | |
| 599 | + } else { | |
| 600 | + container.append( input ); | |
| 601 | + } | |
| 602 | + } | |
| 603 | + | |
| 948 | 604 | afterFormSubmitted( object, response ); |
| 949 | 605 | }, |
| 950 | 606 | delay |
| 951 | 607 | ); |
| @@ -950,8 +606,9 @@ | ||
| 950 | 606 | delay |
| 951 | 607 | ); |
| 952 | 608 | } else if ( Object.keys( response.errors ).length ) { |
| 953 | 609 | // errors were returned |
| 610 | + | |
| 954 | 611 | removeSubmitLoading( jQuery( object ), 'enable' ); |
| 955 | 612 | |
| 956 | 613 | //show errors |
| 957 | 614 | contSubmit = true; |
| @@ -959,14 +616,13 @@ | ||
| 959 | 616 | |
| 960 | 617 | $fieldCont = null; |
| 961 | 618 | |
| 962 | 619 | for ( key in response.errors ) { |
| 963 | - const fieldContEl = object.querySelector( '#frm_field_' + key + '_container' ); | |
| 964 | - $fieldCont = fieldContEl ? jQuery( fieldContEl ) : jQuery(); | |
| 620 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 965 | 621 | |
| 966 | 622 | 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 | |
| 623 | + if ( ! $fieldCont.is( ':visible' ) ) { | |
| 624 | + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); | |
| 969 | 625 | if ( inCollapsedSection.length ) { |
| 970 | 626 | frmTrigger = inCollapsedSection.prev(); |
| 971 | 627 | if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { |
| 972 | 628 | // If the frmTrigger object is the section description, check to see if the previous element is the trigger |
| @@ -975,9 +631,9 @@ | ||
| 975 | 631 | frmTrigger.trigger( 'click' ); |
| 976 | 632 | } |
| 977 | 633 | } |
| 978 | 634 | |
| 979 | - if ( $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is | |
| 635 | + if ( $fieldCont.is( ':visible' ) ) { | |
| 980 | 636 | addFieldError( $fieldCont, key, response.errors ); |
| 981 | 637 | contSubmit = false; |
| 982 | 638 | } |
| 983 | 639 | } |
| @@ -982,10 +638,11 @@ | ||
| 982 | 638 | } |
| 983 | 639 | } |
| 984 | 640 | } |
| 985 | 641 | |
| 986 | - object.querySelectorAll( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).forEach( function( captchaEl ) { | |
| 987 | - const recaptchaID = captchaEl.dataset.rid; | |
| 642 | + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() { | |
| 643 | + var $recaptcha = jQuery( this ), | |
| 644 | + recaptchaID = $recaptcha.data( 'rid' ); | |
| 988 | 645 | |
| 989 | 646 | if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { |
| 990 | 647 | if ( recaptchaID ) { |
| 991 | 648 | grecaptcha.reset( recaptchaID ); |
| @@ -992,29 +649,19 @@ | ||
| 992 | 649 | } else { |
| 993 | 650 | grecaptcha.reset(); |
| 994 | 651 | } |
| 995 | 652 | } |
| 653 | + }); | |
| 996 | 654 | |
| 997 | - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) { | |
| 998 | - hcaptcha.reset(); | |
| 999 | - } | |
| 1000 | - } ); | |
| 655 | + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 1001 | 656 | |
| 1002 | - if ( window.turnstile ) { | |
| 1003 | - object.querySelectorAll( '.frm-cf-turnstile' ).forEach( | |
| 1004 | - turnstileField => turnstileField.dataset.rid && turnstile.reset( turnstileField.dataset.rid ) | |
| 1005 | - ); | |
| 1006 | - } | |
| 1007 | - | |
| 1008 | - jQuery( document ).trigger( 'frmFormErrors', [ object, response ] ); | |
| 1009 | - | |
| 1010 | - fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) ); | |
| 657 | + fieldset.removeClass( 'frm_doing_ajax' ); | |
| 1011 | 658 | scrollToFirstField( object ); |
| 1012 | 659 | |
| 1013 | 660 | if ( contSubmit ) { |
| 1014 | 661 | object.submit(); |
| 1015 | 662 | } else { |
| 1016 | - object.insertAdjacentHTML( 'afterbegin', response.error_message ); | |
| 663 | + jQuery( object ).prepend( response.error_message ); | |
| 1017 | 664 | checkForErrorsAndMaybeSetFocus(); |
| 1018 | 665 | } |
| 1019 | 666 | } else { |
| 1020 | 667 | // there may have been a plugin conflict, or the form is not set to submit with ajax |
| @@ -1025,11 +672,9 @@ | ||
| 1025 | 672 | } |
| 1026 | 673 | }; |
| 1027 | 674 | |
| 1028 | 675 | error = function() { |
| 1029 | - object.querySelectorAll( 'input[type="submit"], input[type="button"]' ).forEach( | |
| 1030 | - button => button.disabled = false | |
| 1031 | - ); | |
| 676 | + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false ); | |
| 1032 | 677 | object.submit(); |
| 1033 | 678 | }; |
| 1034 | 679 | |
| 1035 | 680 | postToAjaxUrl( object, data, success, error ); |
| @@ -1035,15 +680,15 @@ | ||
| 1035 | 680 | postToAjaxUrl( object, data, success, error ); |
| 1036 | 681 | } |
| 1037 | 682 | |
| 1038 | 683 | function postToAjaxUrl( form, data, success, error ) { |
| 1039 | - let ajaxUrl, action, ajaxParams; | |
| 684 | + var ajaxUrl, action, ajaxParams; | |
| 1040 | 685 | |
| 1041 | - ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase | |
| 686 | + ajaxUrl = frm_js.ajax_url; | |
| 1042 | 687 | action = form.getAttribute( 'action' ); |
| 1043 | 688 | |
| 1044 | 689 | if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) { |
| 1045 | - ajaxUrl = action.split( '?action=frm_forms_preview' )[ 0 ]; | |
| 690 | + ajaxUrl = action.split( '?action=frm_forms_preview' )[0]; | |
| 1046 | 691 | } |
| 1047 | 692 | |
| 1048 | 693 | ajaxParams = { |
| 1049 | 694 | type: 'POST', |
| @@ -1055,54 +700,34 @@ | ||
| 1055 | 700 | if ( 'function' === typeof error ) { |
| 1056 | 701 | ajaxParams.error = error; |
| 1057 | 702 | } |
| 1058 | 703 | |
| 1059 | - jQuery.ajax( ajaxParams ); // eslint-disable-line no-jquery/no-ajax | |
| 704 | + jQuery.ajax( ajaxParams ); | |
| 1060 | 705 | } |
| 1061 | 706 | |
| 1062 | 707 | 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 ] ); | |
| 708 | + var formCompleted = jQuery( response.content ).find( '.frm_message' ); | |
| 709 | + if ( formCompleted.length ) { | |
| 710 | + jQuery( document ).trigger( 'frmFormComplete', [ object, response ]); | |
| 1068 | 711 | } else { |
| 1069 | - jQuery( document ).trigger( 'frmPageChanged', [ object, response ] ); | |
| 712 | + jQuery( document ).trigger( 'frmPageChanged', [ object, response ]); | |
| 1070 | 713 | } |
| 1071 | 714 | } |
| 1072 | 715 | |
| 1073 | - /** | |
| 1074 | - * Trigger an event before the form is replaced with a success message. | |
| 1075 | - * | |
| 1076 | - * @since 6.9 | |
| 1077 | - * | |
| 1078 | - * @param {HTMLElement} object The form. | |
| 1079 | - * @param {Object} response The response from submitting the form with AJAX. | |
| 1080 | - * @return {void} | |
| 1081 | - */ | |
| 1082 | - 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 } ); | |
| 1088 | - } | |
| 1089 | - } | |
| 1090 | - | |
| 1091 | 716 | function removeAddedScripts( formContainer, formID ) { |
| 1092 | - const endReplace = document.querySelectorAll( '.frm_end_ajax_' + formID ); | |
| 717 | + var endReplace = jQuery( '.frm_end_ajax_' + formID ); | |
| 1093 | 718 | if ( endReplace.length ) { |
| 1094 | 719 | formContainer.nextUntil( '.frm_end_ajax_' + formID ).remove(); |
| 1095 | - endReplace.forEach( el => el.remove() ); | |
| 720 | + endReplace.remove(); | |
| 1096 | 721 | } |
| 1097 | 722 | } |
| 1098 | 723 | |
| 1099 | 724 | function maybeSlideOut( oldContent, newContent ) { |
| 1100 | - let c, | |
| 725 | + var c, | |
| 1101 | 726 | newClass = 'frm_slideout'; |
| 1102 | - if ( newContent.includes( ' frm_slide' ) ) { | |
| 727 | + if ( newContent.indexOf( ' frm_slide' ) !== -1 ) { | |
| 1103 | 728 | c = oldContent.children(); |
| 1104 | - if ( newContent.includes( ' frm_going_back' ) ) { | |
| 729 | + if ( newContent.indexOf( ' frm_going_back' ) !== -1 ) { | |
| 1105 | 730 | newClass += ' frm_going_back'; |
| 1106 | 731 | } |
| 1107 | 732 | c.removeClass( 'frm_going_back' ); |
| 1108 | 733 | c.addClass( newClass ); |
| @@ -1111,17 +736,17 @@ | ||
| 1111 | 736 | return 0; |
| 1112 | 737 | } |
| 1113 | 738 | |
| 1114 | 739 | function addUrlParam( response ) { |
| 1115 | - let url; | |
| 740 | + var url; | |
| 1116 | 741 | if ( history.pushState && typeof response.page !== 'undefined' ) { |
| 1117 | 742 | url = addQueryVar( 'frm_page', response.page ); |
| 1118 | - window.history.pushState( { html: response.html }, '', '?' + url ); | |
| 743 | + window.history.pushState({ 'html': response.html }, '', '?' + url ); | |
| 1119 | 744 | } |
| 1120 | 745 | } |
| 1121 | 746 | |
| 1122 | 747 | function addQueryVar( key, value ) { |
| 1123 | - let kvp, i, x; | |
| 748 | + var kvp, i, x; | |
| 1124 | 749 | |
| 1125 | 750 | key = encodeURI( key ); |
| 1126 | 751 | value = encodeURI( value ); |
| 1127 | 752 | |
| @@ -1128,13 +753,13 @@ | ||
| 1128 | 753 | kvp = document.location.search.substr( 1 ).split( '&' ); |
| 1129 | 754 | |
| 1130 | 755 | i = kvp.length; |
| 1131 | 756 | while ( i-- ) { |
| 1132 | - x = kvp[ i ].split( '=' ); | |
| 757 | + x = kvp[i].split( '=' ); | |
| 1133 | 758 | |
| 1134 | - if ( x[ 0 ] == key ) { | |
| 1135 | - x[ 1 ] = value; | |
| 1136 | - kvp[ i ] = x.join( '=' ); | |
| 759 | + if ( x[0] == key ) { | |
| 760 | + x[1] = value; | |
| 761 | + kvp[i] = x.join( '=' ); | |
| 1137 | 762 | break; |
| 1138 | 763 | } |
| 1139 | 764 | } |
| 1140 | 765 | |
| @@ -1145,143 +770,69 @@ | ||
| 1145 | 770 | return kvp.join( '&' ); |
| 1146 | 771 | } |
| 1147 | 772 | |
| 1148 | 773 | 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 | - } | |
| 774 | + var input, id, describedBy, roleString; | |
| 775 | + if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) { | |
| 776 | + $fieldCont.addClass( 'frm_blank_field' ); | |
| 777 | + input = $fieldCont.find( 'input, select, textarea' ); | |
| 778 | + id = 'frm_error_field_' + key; | |
| 779 | + describedBy = input.attr( 'aria-describedby' ); | |
| 1154 | 780 | |
| 1155 | - container.classList.add( 'frm_blank_field' ); | |
| 1156 | - const input = container.querySelector( 'input, select, textarea' ); | |
| 1157 | - id = getErrorElementId( key, input ); | |
| 1158 | - | |
| 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 ]; | |
| 781 | + if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase | |
| 782 | + frmThemeOverride_frmPlaceError( key, jsErrors ); | |
| 1167 | 783 | } 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 ); | |
| 784 | + if ( -1 !== jsErrors[key].indexOf( '<div' ) ) { | |
| 785 | + $fieldCont.append( | |
| 786 | + jsErrors[key] | |
| 787 | + ); | |
| 788 | + } else { | |
| 789 | + roleString = frm_js.include_alert_role ? 'role="alert"' : ''; | |
| 790 | + $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' ); | |
| 791 | + } | |
| 1172 | 792 | |
| 1173 | - if ( input ) { | |
| 1174 | - if ( ! describedBy ) { | |
| 793 | + if ( typeof describedBy === 'undefined' ) { | |
| 1175 | 794 | describedBy = id; |
| 1176 | - } else if ( ! describedBy.includes( id ) && ! describedBy.includes( 'frm_error_field_' ) ) { | |
| 1177 | - const errorFirst = input.dataset.errorFirst; | |
| 1178 | - if ( errorFirst === '0' ) { | |
| 1179 | - describedBy = describedBy + ' ' + id; | |
| 1180 | - } else { | |
| 1181 | - describedBy = id + ' ' + describedBy; | |
| 1182 | - } | |
| 795 | + } else if ( describedBy.indexOf( id ) === -1 ) { | |
| 796 | + describedBy = describedBy + ' ' + id; | |
| 1183 | 797 | } |
| 1184 | - input.setAttribute( 'aria-describedby', describedBy ); | |
| 798 | + input.attr( 'aria-describedby', describedBy ); | |
| 1185 | 799 | } |
| 1186 | - } | |
| 800 | + input.attr( 'aria-invalid', true ); | |
| 801 | + input.attr( 'aria-describedby', id ); | |
| 1187 | 802 | |
| 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 | - } | |
| 803 | + jQuery( document ).trigger( 'frmAddFieldError', [ $fieldCont, key, jsErrors ]); | |
| 1197 | 804 | } |
| 1198 | - | |
| 1199 | - jQuery( document ).trigger( 'frmAddFieldError', [ jQuery( container ), key, jsErrors ] ); | |
| 1200 | 805 | } |
| 1201 | 806 | |
| 1202 | - /** | |
| 1203 | - * Get the ID to use for an error element added when submitting with AJAX. | |
| 1204 | - * | |
| 1205 | - * @param {string} key | |
| 1206 | - * @param {HTMLElement} input | |
| 1207 | - * @return {string} The ID to use for the error element. | |
| 1208 | - */ | |
| 1209 | - function getErrorElementId( key, input ) { | |
| 1210 | - if ( isNaN( key ) || ! input || ! input.id ) { | |
| 1211 | - // If key isn't a number, assume it's already in the right format. | |
| 1212 | - return 'frm_error_field_' + key; | |
| 1213 | - } | |
| 1214 | - return 'frm_error_' + input.id; | |
| 1215 | - } | |
| 807 | + function removeFieldError( $fieldCont ) { | |
| 808 | + var errorMessage = $fieldCont.find( '.frm_error' ), | |
| 809 | + errorId = errorMessage.attr( 'id' ), | |
| 810 | + input = $fieldCont.find( 'input, select, textarea' ), | |
| 811 | + describedBy = input.attr( 'aria-describedby' ); | |
| 1216 | 812 | |
| 1217 | - /** | |
| 1218 | - * Removes errors before validating with JS. | |
| 1219 | - * This prevents issues with stale errors that has since been fixed. | |
| 1220 | - * | |
| 1221 | - * @param {HTMLElement|jQuery} fieldCont Field container element. | |
| 1222 | - * @return {void} | |
| 1223 | - */ | |
| 1224 | - function removeFieldError( fieldCont ) { | |
| 1225 | - const container = fieldCont instanceof jQuery ? fieldCont.get( 0 ) : fieldCont; | |
| 1226 | - if ( ! container ) { | |
| 1227 | - return; | |
| 1228 | - } | |
| 813 | + $fieldCont.removeClass( 'frm_blank_field has-error' ); | |
| 814 | + errorMessage.remove(); | |
| 815 | + input.attr( 'aria-invalid', false ); | |
| 816 | + input.removeAttr( 'aria-describedby' ); | |
| 1229 | 817 | |
| 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 | - } | |
| 818 | + if ( typeof describedBy !== 'undefined' ) { | |
| 819 | + describedBy = describedBy.replace( errorId, '' ); | |
| 820 | + input.attr( 'aria-describedby', describedBy ); | |
| 1246 | 821 | } |
| 1247 | - | |
| 1248 | - if ( errorMessage ) { | |
| 1249 | - errorMessage.remove(); | |
| 1250 | - } | |
| 1251 | - | |
| 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 | - } | |
| 1260 | - } | |
| 1261 | 822 | } |
| 1262 | 823 | |
| 1263 | 824 | 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() ); | |
| 825 | + jQuery( '.form-field' ).removeClass( 'frm_blank_field has-error' ); | |
| 826 | + jQuery( '.form-field .frm_error' ).replaceWith( '' ); | |
| 827 | + jQuery( '.frm_error_style' ).remove(); | |
| 1269 | 828 | } |
| 1270 | 829 | |
| 1271 | - /** | |
| 1272 | - * @param {HTMLElement|Object} object Form object. | |
| 1273 | - * @return {void} | |
| 1274 | - */ | |
| 1275 | 830 | function scrollToFirstField( object ) { |
| 1276 | - if ( 'function' === typeof object.get ) { | |
| 1277 | - // Get the HTMLElement from a jQuery object. | |
| 1278 | - object = object.get( 0 ); | |
| 831 | + var field = jQuery( object ).find( '.frm_blank_field' ).first(); | |
| 832 | + if ( field.length ) { | |
| 833 | + frmFrontForm.scrollMsg( field, object, true ); | |
| 1279 | 834 | } |
| 1280 | - const field = object.querySelector( '.frm_blank_field' ); | |
| 1281 | - if ( field ) { | |
| 1282 | - frmFrontForm.scrollMsg( jQuery( field ), object, true ); | |
| 1283 | - } | |
| 1284 | 835 | } |
| 1285 | 836 | |
| 1286 | 837 | function showSubmitLoading( $object ) { |
| 1287 | 838 | showLoadingIndicator( $object ); |
| @@ -1289,9 +840,9 @@ | ||
| 1289 | 840 | disableSaveDraft( $object ); |
| 1290 | 841 | } |
| 1291 | 842 | |
| 1292 | 843 | function showLoadingIndicator( $object ) { |
| 1293 | - if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) { // eslint-disable-line no-jquery/no-class | |
| 844 | + if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) { | |
| 1294 | 845 | addLoadingClass( $object ); |
| 1295 | 846 | $object.trigger( 'frmStartFormLoading' ); |
| 1296 | 847 | } |
| 1297 | 848 | } |
| @@ -1296,11 +847,11 @@ | ||
| 1296 | 847 | } |
| 1297 | 848 | } |
| 1298 | 849 | |
| 1299 | 850 | function addLoadingClass( $object ) { |
| 1300 | - const loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form'; | |
| 851 | + var loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form'; | |
| 1301 | 852 | |
| 1302 | - $object.addClass( loadingClass ); // eslint-disable-line no-jquery/no-class | |
| 853 | + $object.addClass( loadingClass ); | |
| 1303 | 854 | } |
| 1304 | 855 | |
| 1305 | 856 | function isGoingToPrevPage( $object ) { |
| 1306 | 857 | return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) ); |
| @@ -1305,39 +856,101 @@ | ||
| 1305 | 856 | function isGoingToPrevPage( $object ) { |
| 1306 | 857 | return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) ); |
| 1307 | 858 | } |
| 1308 | 859 | |
| 1309 | - function removeSubmitLoading( _, enable, processesRunning ) { | |
| 860 | + function removeSubmitLoading( $object, enable, processesRunning ) { | |
| 861 | + var loadingForm; | |
| 862 | + | |
| 1310 | 863 | if ( processesRunning > 0 ) { |
| 1311 | 864 | return; |
| 1312 | 865 | } |
| 1313 | 866 | |
| 1314 | - document.querySelectorAll( '.frm_loading_form' ).forEach( function( form ) { | |
| 1315 | - form.classList.remove( 'frm_loading_form', 'frm_loading_prev' ); | |
| 1316 | - jQuery( form ).trigger( 'frmEndFormLoading' ); | |
| 867 | + loadingForm = jQuery( '.frm_loading_form' ); | |
| 868 | + loadingForm.removeClass( 'frm_loading_form' ); | |
| 869 | + loadingForm.removeClass( 'frm_loading_prev' ); | |
| 1317 | 870 | |
| 1318 | - if ( enable === 'enable' ) { | |
| 1319 | - enableSubmitButton( form ); | |
| 1320 | - enableSaveDraft( form ); | |
| 871 | + loadingForm.trigger( 'frmEndFormLoading' ); | |
| 872 | + | |
| 873 | + if ( enable === 'enable' ) { | |
| 874 | + enableSubmitButton( loadingForm ); | |
| 875 | + enableSaveDraft( loadingForm ); | |
| 876 | + } | |
| 877 | + } | |
| 878 | + | |
| 879 | + function showFileLoading( object ) { | |
| 880 | + var fileval, | |
| 881 | + loading = document.getElementById( 'frm_loading' ); | |
| 882 | + if ( loading !== null ) { | |
| 883 | + fileval = jQuery( object ).find( 'input[type=file]' ).val(); | |
| 884 | + if ( typeof fileval !== 'undefined' && fileval !== '' ) { | |
| 885 | + setTimeout( function() { | |
| 886 | + jQuery( loading ).fadeIn( 'slow' ); | |
| 887 | + }, 2000 ); | |
| 1321 | 888 | } |
| 1322 | - } ); | |
| 889 | + } | |
| 1323 | 890 | } |
| 1324 | 891 | |
| 1325 | - function showFileLoading( object ) { | |
| 1326 | - const loading = document.getElementById( 'frm_loading' ); | |
| 1327 | - if ( loading === null ) { | |
| 1328 | - return; | |
| 892 | + function clearDefault() { | |
| 893 | + /*jshint validthis:true */ | |
| 894 | + toggleDefault( jQuery( this ), 'clear' ); | |
| 895 | + } | |
| 896 | + | |
| 897 | + function replaceDefault() { | |
| 898 | + /*jshint validthis:true */ | |
| 899 | + toggleDefault( jQuery( this ), 'replace' ); | |
| 900 | + } | |
| 901 | + | |
| 902 | + function toggleDefault( $thisField, e ) { | |
| 903 | + // TODO: Fix this for a default value that is a number or array | |
| 904 | + var thisVal, | |
| 905 | + v = $thisField.data( 'frmval' ).replace( /(\n|\r\n)/g, '\r' ); | |
| 906 | + if ( v === '' || typeof v === 'undefined' ) { | |
| 907 | + return false; | |
| 1329 | 908 | } |
| 909 | + thisVal = $thisField.val().replace( /(\n|\r\n)/g, '\r' ); | |
| 1330 | 910 | |
| 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 ); | |
| 911 | + if ( 'replace' === e ) { | |
| 912 | + if ( thisVal === '' ) { | |
| 913 | + $thisField.addClass( 'frm_default' ).val( v ); | |
| 914 | + } | |
| 915 | + } else if ( thisVal == v ) { | |
| 916 | + $thisField.removeClass( 'frm_default' ).val( '' ); | |
| 1337 | 917 | } |
| 1338 | 918 | } |
| 1339 | 919 | |
| 920 | + function resendEmail() { | |
| 921 | + /*jshint validthis:true */ | |
| 922 | + var $link = jQuery( this ), | |
| 923 | + entryId = this.getAttribute( 'data-eid' ), | |
| 924 | + formId = this.getAttribute( 'data-fid' ), | |
| 925 | + label = $link.find( '.frm_link_label' ); | |
| 926 | + if ( label.length < 1 ) { | |
| 927 | + label = $link; | |
| 928 | + } | |
| 929 | + label.append( '<span class="frm-wait"></span>' ); | |
| 930 | + | |
| 931 | + jQuery.ajax({ | |
| 932 | + type: 'POST', | |
| 933 | + url: frm_js.ajax_url, | |
| 934 | + data: { | |
| 935 | + action: 'frm_entries_send_email', | |
| 936 | + entry_id: entryId, | |
| 937 | + form_id: formId, | |
| 938 | + nonce: frm_js.nonce | |
| 939 | + }, | |
| 940 | + success: function( msg ) { | |
| 941 | + var admin = document.getElementById( 'wpbody' ); | |
| 942 | + if ( admin === null ) { | |
| 943 | + label.html( msg ); | |
| 944 | + } else { | |
| 945 | + label.html( '' ); | |
| 946 | + $link.after( msg ); | |
| 947 | + } | |
| 948 | + } | |
| 949 | + }); | |
| 950 | + return false; | |
| 951 | + } | |
| 952 | + | |
| 1340 | 953 | /********************************************** |
| 1341 | 954 | * General Helpers |
| 1342 | 955 | *********************************************/ |
| 1343 | 956 | |
| @@ -1342,12 +955,109 @@ | ||
| 1342 | 955 | *********************************************/ |
| 1343 | 956 | |
| 1344 | 957 | function confirmClick() { |
| 1345 | 958 | /*jshint validthis:true */ |
| 1346 | - const message = this.dataset.frmconfirm; | |
| 959 | + var message = jQuery( this ).data( 'frmconfirm' ); | |
| 1347 | 960 | return confirm( message ); |
| 1348 | 961 | } |
| 1349 | 962 | |
| 963 | + function toggleDiv() { | |
| 964 | + /*jshint validthis:true */ | |
| 965 | + var div = jQuery( this ).data( 'frmtoggle' ); | |
| 966 | + if ( jQuery( div ).is( ':visible' ) ) { | |
| 967 | + jQuery( div ).slideUp( 'fast' ); | |
| 968 | + } else { | |
| 969 | + jQuery( div ).slideDown( 'fast' ); | |
| 970 | + } | |
| 971 | + return false; | |
| 972 | + } | |
| 973 | + | |
| 974 | + /********************************************** | |
| 975 | + * Fallback functions | |
| 976 | + *********************************************/ | |
| 977 | + | |
| 978 | + function addIndexOfFallbackForIE8() { | |
| 979 | + var len, from; | |
| 980 | + | |
| 981 | + if ( ! Array.prototype.indexOf ) { | |
| 982 | + Array.prototype.indexOf = function( elt /*, from*/ ) { | |
| 983 | + len = this.length >>> 0; | |
| 984 | + | |
| 985 | + from = Number( arguments[1]) || 0; | |
| 986 | + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from ); | |
| 987 | + if ( from < 0 ) { | |
| 988 | + from += len; | |
| 989 | + } | |
| 990 | + | |
| 991 | + for ( ; from < len; from++ ) { | |
| 992 | + if ( from in this && this[from] === elt ) { | |
| 993 | + return from; | |
| 994 | + } | |
| 995 | + } | |
| 996 | + return -1; | |
| 997 | + }; | |
| 998 | + } | |
| 999 | + } | |
| 1000 | + | |
| 1001 | + function addTrimFallbackForIE8() { | |
| 1002 | + if ( typeof String.prototype.trim !== 'function' ) { | |
| 1003 | + String.prototype.trim = function() { | |
| 1004 | + return this.replace( /^\s+|\s+$/g, '' ); | |
| 1005 | + }; | |
| 1006 | + } | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + function addFilterFallbackForIE8() { | |
| 1010 | + var t, len, res, thisp, i, val; | |
| 1011 | + | |
| 1012 | + if ( ! Array.prototype.filter ) { | |
| 1013 | + | |
| 1014 | + Array.prototype.filter = function( fun /*, thisp */ ) { | |
| 1015 | + | |
| 1016 | + if ( this === void 0 || this === null ) { | |
| 1017 | + throw new TypeError(); | |
| 1018 | + } | |
| 1019 | + | |
| 1020 | + t = Object( this ); | |
| 1021 | + len = t.length >>> 0; | |
| 1022 | + if ( typeof fun !== 'function' ) { | |
| 1023 | + throw new TypeError(); | |
| 1024 | + } | |
| 1025 | + | |
| 1026 | + res = []; | |
| 1027 | + thisp = arguments[1]; | |
| 1028 | + for ( i = 0; i < len; i++ ) { | |
| 1029 | + if ( i in t ) { | |
| 1030 | + val = t[i]; // in case fun mutates this | |
| 1031 | + if ( fun.call( thisp, val, i, t ) ) { | |
| 1032 | + res.push( val ); | |
| 1033 | + } | |
| 1034 | + } | |
| 1035 | + } | |
| 1036 | + | |
| 1037 | + return res; | |
| 1038 | + }; | |
| 1039 | + } | |
| 1040 | + } | |
| 1041 | + | |
| 1042 | + function addKeysFallbackForIE8() { | |
| 1043 | + var keys, i; | |
| 1044 | + | |
| 1045 | + if ( ! Object.keys ) { | |
| 1046 | + Object.keys = function( obj ) { | |
| 1047 | + keys = []; | |
| 1048 | + | |
| 1049 | + for ( i in obj ) { | |
| 1050 | + if ( obj.hasOwnProperty( i ) ) { | |
| 1051 | + keys.push( i ); | |
| 1052 | + } | |
| 1053 | + } | |
| 1054 | + | |
| 1055 | + return keys; | |
| 1056 | + }; | |
| 1057 | + } | |
| 1058 | + } | |
| 1059 | + | |
| 1350 | 1060 | /** |
| 1351 | 1061 | * Check for -webkit-box-shadow css value for input:-webkit-autofill selector. |
| 1352 | 1062 | * If this is a match, the User is autofilling the input on a Webkit browser. |
| 1353 | 1063 | * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete. |
| @@ -1352,12 +1062,11 @@ | ||
| 1352 | 1062 | * If this is a match, the User is autofilling the input on a Webkit browser. |
| 1353 | 1063 | * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete. |
| 1354 | 1064 | */ |
| 1355 | 1065 | function onHoneypotFieldChange() { |
| 1356 | - /*jshint validthis:true */ | |
| 1357 | - const css = window.getComputedStyle( this ).boxShadow; | |
| 1358 | - if ( css && css.match( /inset/ ) ) { | |
| 1359 | - this.remove(); | |
| 1066 | + var css = jQuery( this ).css( 'box-shadow' ); | |
| 1067 | + if ( css.match( /inset/ ) ) { | |
| 1068 | + this.parentNode.removeChild( this ); | |
| 1360 | 1069 | } |
| 1361 | 1070 | } |
| 1362 | 1071 | |
| 1363 | 1072 | /** |
| @@ -1378,41 +1087,18 @@ | ||
| 1378 | 1087 | if ( ! label ) { |
| 1379 | 1088 | return; |
| 1380 | 1089 | } |
| 1381 | 1090 | |
| 1382 | - label.addEventListener( 'click', function() { | |
| 1091 | + label.addEventListener( 'click', function( e ) { | |
| 1383 | 1092 | inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus(); |
| 1384 | - } ); | |
| 1385 | - } ); | |
| 1093 | + }); | |
| 1094 | + }); | |
| 1386 | 1095 | } |
| 1387 | 1096 | |
| 1388 | - /** | |
| 1389 | - * Sets focus on a the first subfield of a combo field that has an error. | |
| 1390 | - * | |
| 1391 | - * @since 6.16.3 | |
| 1392 | - * | |
| 1393 | - * @param {HTMLElement} element | |
| 1394 | - * @return {boolean} True if the focus was set on a combo field. | |
| 1395 | - */ | |
| 1396 | - function maybeFocusOnComboSubField( element ) { | |
| 1397 | - if ( 'FIELDSET' !== element.nodeName ) { | |
| 1398 | - return false; | |
| 1399 | - } | |
| 1400 | - if ( ! element.querySelector( '.frm_combo_inputs_container' ) ) { | |
| 1401 | - return false; | |
| 1402 | - } | |
| 1403 | - const comboSubfield = element.querySelector( '[aria-invalid="true"]' ); | |
| 1404 | - if ( comboSubfield ) { | |
| 1405 | - focusInput( comboSubfield ); | |
| 1406 | - return true; | |
| 1407 | - } | |
| 1408 | - return false; | |
| 1409 | - } | |
| 1410 | - | |
| 1411 | 1097 | function checkForErrorsAndMaybeSetFocus() { |
| 1412 | - let errors, element, timeoutCallback; | |
| 1098 | + var errors, element, timeoutCallback; | |
| 1413 | 1099 | |
| 1414 | - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase | |
| 1100 | + if ( ! frm_js.focus_first_error ) { | |
| 1415 | 1101 | return; |
| 1416 | 1102 | } |
| 1417 | 1103 | |
| 1418 | 1104 | errors = document.querySelectorAll( '.frm_form_field .frm_error' ); |
| @@ -1419,24 +1105,20 @@ | ||
| 1419 | 1105 | if ( ! errors.length ) { |
| 1420 | 1106 | return; |
| 1421 | 1107 | } |
| 1422 | 1108 | |
| 1423 | - element = errors[ 0 ]; | |
| 1109 | + element = errors[0]; | |
| 1424 | 1110 | do { |
| 1425 | 1111 | element = element.previousSibling; |
| 1426 | 1112 | if ( -1 !== [ 'input', 'select', 'textarea' ].indexOf( element.nodeName.toLowerCase() ) ) { |
| 1427 | - focusInput( element ); | |
| 1113 | + element.focus(); | |
| 1428 | 1114 | break; |
| 1429 | 1115 | } |
| 1430 | 1116 | |
| 1431 | - if ( maybeFocusOnComboSubField( element ) ) { | |
| 1432 | - break; | |
| 1433 | - } | |
| 1434 | - | |
| 1435 | 1117 | if ( 'undefined' !== typeof element.classList ) { |
| 1436 | 1118 | if ( element.classList.contains( 'html-active' ) ) { |
| 1437 | 1119 | timeoutCallback = function() { |
| 1438 | - const textarea = element.querySelector( 'textarea' ); | |
| 1120 | + var textarea = element.querySelector( 'textarea' ); | |
| 1439 | 1121 | if ( null !== textarea ) { |
| 1440 | 1122 | textarea.focus(); |
| 1441 | 1123 | } |
| 1442 | 1124 | }; |
| @@ -1443,14 +1125,8 @@ | ||
| 1443 | 1125 | } else if ( element.classList.contains( 'tmce-active' ) ) { |
| 1444 | 1126 | timeoutCallback = function() { |
| 1445 | 1127 | tinyMCE.activeEditor.focus(); |
| 1446 | 1128 | }; |
| 1447 | - } else if ( element.classList.contains( 'frm_opt_container' ) ) { | |
| 1448 | - const firstInput = element.querySelector( 'input' ); | |
| 1449 | - if ( firstInput ) { | |
| 1450 | - focusInput( firstInput ); | |
| 1451 | - break; | |
| 1452 | - } | |
| 1453 | 1129 | } |
| 1454 | 1130 | |
| 1455 | 1131 | if ( 'function' === typeof timeoutCallback ) { |
| 1456 | 1132 | setTimeout( timeoutCallback, 0 ); |
| @@ -1459,313 +1135,32 @@ | ||
| 1459 | 1135 | } |
| 1460 | 1136 | } while ( element.previousSibling ); |
| 1461 | 1137 | } |
| 1462 | 1138 | |
| 1463 | - /** | |
| 1464 | - * Focus a visible input, or possibly delay the focus event until the form has faded in. | |
| 1465 | - * | |
| 1466 | - * @since 6.16.3 | |
| 1467 | - * | |
| 1468 | - * @param {HTMLElement} input | |
| 1469 | - * @return {void} | |
| 1470 | - */ | |
| 1471 | - function focusInput( input ) { | |
| 1472 | - if ( input.offsetParent !== null ) { | |
| 1473 | - input.focus(); | |
| 1474 | - } else { | |
| 1475 | - triggerCustomEvent( document, 'frmMaybeDelayFocus', { input } ); | |
| 1476 | - } | |
| 1477 | - } | |
| 1139 | + return { | |
| 1140 | + init: function() { | |
| 1141 | + jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); | |
| 1142 | + jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm ); | |
| 1478 | 1143 | |
| 1479 | - /** | |
| 1480 | - * Does the same as jQuery( document ).on( 'event', 'selector', handler ). | |
| 1481 | - * | |
| 1482 | - * @since 5.4 | |
| 1483 | - * | |
| 1484 | - * @param {string} event Event name. | |
| 1485 | - * @param {string} selector Selector. | |
| 1486 | - * @param {Function} handler Handler. | |
| 1487 | - * @param {boolean | Object} options Options to be added to `addEventListener()` method. Default is `false`. | |
| 1488 | - */ | |
| 1489 | - function documentOn( event, selector, handler, options ) { | |
| 1490 | - if ( 'undefined' === typeof options ) { | |
| 1491 | - options = false; | |
| 1492 | - } | |
| 1493 | - | |
| 1494 | - document.addEventListener( event, function( e ) { | |
| 1495 | - let target; | |
| 1496 | - | |
| 1497 | - // loop parent nodes from the target to the delegation node. | |
| 1498 | - for ( target = e.target; target && target != this; target = target.parentNode ) { | |
| 1499 | - if ( target.matches && target.matches( selector ) ) { | |
| 1500 | - handler.call( target, e ); | |
| 1501 | - break; | |
| 1144 | + jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() { | |
| 1145 | + if ( jQuery( this ).val() === '' ) { | |
| 1146 | + jQuery( this ).trigger( 'blur' ); | |
| 1502 | 1147 | } |
| 1503 | - } | |
| 1504 | - }, options ); | |
| 1505 | - } | |
| 1148 | + }); | |
| 1506 | 1149 | |
| 1507 | - function initFloatingLabels() { | |
| 1508 | - let checkFloatLabel, checkDropdownLabel, runOnLoad, selector, floatClass; | |
| 1150 | + jQuery( document ).on( 'focus', '.frm_toggle_default', clearDefault ); | |
| 1151 | + jQuery( document ).on( 'blur', '.frm_toggle_default', replaceDefault ); | |
| 1152 | + jQuery( '.frm_toggle_default' ).trigger( 'blur' ); | |
| 1509 | 1153 | |
| 1510 | - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea'; | |
| 1511 | - floatClass = 'frm_label_float_top'; | |
| 1154 | + jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail ); | |
| 1512 | 1155 | |
| 1513 | - checkFloatLabel = function( input ) { | |
| 1514 | - let container, shouldFloatTop, firstOpt; | |
| 1515 | - | |
| 1516 | - container = input.closest( '.frm_inside_container' ); | |
| 1517 | - if ( ! container ) { | |
| 1518 | - return; | |
| 1519 | - } | |
| 1520 | - | |
| 1521 | - shouldFloatTop = input.value || document.activeElement === input; | |
| 1522 | - | |
| 1523 | - container.classList.toggle( floatClass, shouldFloatTop ); | |
| 1524 | - | |
| 1525 | - if ( 'SELECT' === input.tagName ) { | |
| 1526 | - firstOpt = input.querySelector( 'option:first-child' ); | |
| 1527 | - | |
| 1528 | - if ( shouldFloatTop ) { | |
| 1529 | - if ( firstOpt.hasAttribute( 'data-label' ) ) { | |
| 1530 | - firstOpt.textContent = firstOpt.getAttribute( 'data-label' ); | |
| 1531 | - firstOpt.removeAttribute( 'data-label' ); | |
| 1532 | - } | |
| 1533 | - } else if ( firstOpt.textContent ) { | |
| 1534 | - firstOpt.setAttribute( 'data-label', firstOpt.textContent ); | |
| 1535 | - firstOpt.textContent = ''; | |
| 1536 | - } | |
| 1537 | - } | |
| 1538 | - }; | |
| 1539 | - | |
| 1540 | - checkDropdownLabel = function() { | |
| 1541 | - document.querySelectorAll( '.frm-show-form .frm_inside_container:not(.' + floatClass + ') select' ).forEach( function( input ) { | |
| 1542 | - const firstOpt = input.querySelector( 'option:first-child' ); | |
| 1543 | - | |
| 1544 | - if ( firstOpt.textContent ) { | |
| 1545 | - firstOpt.setAttribute( 'data-label', firstOpt.textContent ); | |
| 1546 | - firstOpt.textContent = ''; | |
| 1547 | - } | |
| 1548 | - } ); | |
| 1549 | - }; | |
| 1550 | - | |
| 1551 | - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) { | |
| 1552 | - documentOn( | |
| 1553 | - eventName, | |
| 1554 | - selector, | |
| 1555 | - function( event ) { | |
| 1556 | - checkFloatLabel( event.target ); | |
| 1557 | - }, | |
| 1558 | - true | |
| 1559 | - ); | |
| 1560 | - } ); | |
| 1561 | - | |
| 1562 | - runOnLoad = function( firstLoad ) { | |
| 1563 | - if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) { | |
| 1564 | - checkFloatLabel( document.activeElement ); | |
| 1565 | - } else if ( firstLoad ) { | |
| 1566 | - document.querySelectorAll( '.frm_inside_container' ).forEach( | |
| 1567 | - function( container ) { | |
| 1568 | - const input = container.querySelector( 'input, select, textarea' ); | |
| 1569 | - if ( input && '' !== input.value ) { | |
| 1570 | - checkFloatLabel( input ); | |
| 1571 | - } | |
| 1572 | - } | |
| 1573 | - ); | |
| 1574 | - } | |
| 1575 | - | |
| 1576 | - checkDropdownLabel(); | |
| 1577 | - }; | |
| 1578 | - | |
| 1579 | - runOnLoad( true ); | |
| 1580 | - | |
| 1581 | - jQuery( document ).on( 'frmPageChanged', function( event ) { | |
| 1582 | - runOnLoad(); | |
| 1583 | - } ); | |
| 1584 | - | |
| 1585 | - document.addEventListener( 'frm_after_start_over', function( event ) { | |
| 1586 | - runOnLoad(); | |
| 1587 | - } ); | |
| 1588 | - } | |
| 1589 | - | |
| 1590 | - function shouldUpdateValidityMessage( target ) { | |
| 1591 | - if ( 'INPUT' !== target.nodeName ) { | |
| 1592 | - return false; | |
| 1593 | - } | |
| 1594 | - | |
| 1595 | - if ( ! target.dataset.invmsg ) { | |
| 1596 | - return false; | |
| 1597 | - } | |
| 1598 | - | |
| 1599 | - if ( 'text' !== target.getAttribute( 'type' ) ) { | |
| 1600 | - return false; | |
| 1601 | - } | |
| 1602 | - | |
| 1603 | - if ( target.classList.contains( 'frm_verify' ) ) { | |
| 1604 | - return false; | |
| 1605 | - } | |
| 1606 | - | |
| 1607 | - return true; | |
| 1608 | - } | |
| 1609 | - | |
| 1610 | - function maybeClearCustomValidityMessage( event, field ) { | |
| 1611 | - let key, | |
| 1612 | - isInvalid = false; | |
| 1613 | - | |
| 1614 | - if ( ! shouldUpdateValidityMessage( field ) ) { | |
| 1615 | - return; | |
| 1616 | - } | |
| 1617 | - | |
| 1618 | - for ( key in field.validity ) { | |
| 1619 | - if ( 'customError' === key ) { | |
| 1620 | - continue; | |
| 1621 | - } | |
| 1622 | - if ( 'valid' !== key && field.validity[ key ] === true ) { | |
| 1623 | - isInvalid = true; | |
| 1624 | - break; | |
| 1625 | - } | |
| 1626 | - } | |
| 1627 | - | |
| 1628 | - if ( ! isInvalid ) { | |
| 1629 | - field.setCustomValidity( '' ); | |
| 1630 | - } | |
| 1631 | - } | |
| 1632 | - | |
| 1633 | - function maybeShowNewTabFallbackMessage() { | |
| 1634 | - let messageEl; | |
| 1635 | - | |
| 1636 | - if ( ! window.frmShowNewTabFallback ) { | |
| 1637 | - return; | |
| 1638 | - } | |
| 1639 | - | |
| 1640 | - messageEl = document.querySelector( '#frm_form_' + frmShowNewTabFallback.formId + '_container .frm_message' ); | |
| 1641 | - if ( ! messageEl ) { | |
| 1642 | - return; | |
| 1643 | - } | |
| 1644 | - | |
| 1645 | - messageEl.insertAdjacentHTML( 'beforeend', ' ' + frmShowNewTabFallback.message ); | |
| 1646 | - } | |
| 1647 | - | |
| 1648 | - function setCustomValidityMessage() { | |
| 1649 | - let forms, length, index; | |
| 1650 | - | |
| 1651 | - forms = document.getElementsByClassName( 'frm-show-form' ); | |
| 1652 | - length = forms.length; | |
| 1653 | - | |
| 1654 | - for ( index = 0; index < length; ++index ) { | |
| 1655 | - forms[ index ].addEventListener( | |
| 1656 | - 'invalid', | |
| 1657 | - function( event ) { | |
| 1658 | - const target = event.target; | |
| 1659 | - | |
| 1660 | - if ( shouldUpdateValidityMessage( target ) ) { | |
| 1661 | - target.setCustomValidity( target.dataset.invmsg ); | |
| 1662 | - } | |
| 1663 | - }, | |
| 1664 | - true | |
| 1665 | - ); | |
| 1666 | - } | |
| 1667 | - } | |
| 1668 | - | |
| 1669 | - function enableSubmitButtonOnBackButtonPress() { | |
| 1670 | - window.addEventListener( 'pageshow', function( event ) { | |
| 1671 | - if ( event.persisted ) { | |
| 1672 | - document.querySelectorAll( '.frm_loading_form' ).forEach( | |
| 1673 | - function( form ) { | |
| 1674 | - enableSubmitButton( form ); | |
| 1675 | - } | |
| 1676 | - ); | |
| 1677 | - removeSubmitLoading(); | |
| 1678 | - } | |
| 1679 | - } ); | |
| 1680 | - } | |
| 1681 | - | |
| 1682 | - /** | |
| 1683 | - * Destroys the formidable generated global hcaptcha object since it wouldn't otherwise render. | |
| 1684 | - */ | |
| 1685 | - function destroyhCaptcha() { | |
| 1686 | - if ( ! window.hasOwnProperty( 'hcaptcha' ) || ! document.querySelector( '.frm-show-form .h-captcha' ) ) { | |
| 1687 | - return; | |
| 1688 | - } | |
| 1689 | - window.hcaptcha = null; | |
| 1690 | - } | |
| 1691 | - | |
| 1692 | - /** | |
| 1693 | - * @since 6.16.3 | |
| 1694 | - * | |
| 1695 | - * @return {string} Unique key, used for duplicate checks. | |
| 1696 | - */ | |
| 1697 | - function getUniqueKey() { | |
| 1698 | - const uniqueKey = Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) ) | |
| 1699 | - .map( b => b.toString( 16 ).padStart( 2, '0' ) ) | |
| 1700 | - .join( '' ); | |
| 1701 | - const timestamp = Date.now().toString( 16 ); | |
| 1702 | - return uniqueKey + '-' + timestamp; | |
| 1703 | - } | |
| 1704 | - | |
| 1705 | - /** | |
| 1706 | - * Animates the scroll position of the document. | |
| 1707 | - * | |
| 1708 | - * @since 6.20 | |
| 1709 | - * | |
| 1710 | - * @param {number} start | |
| 1711 | - * @param {number} end | |
| 1712 | - * @param {number} duration | |
| 1713 | - * @return {void} | |
| 1714 | - */ | |
| 1715 | - function animateScroll( start, end, duration ) { | |
| 1716 | - if ( ! window.hasOwnProperty( 'performance' ) || ! window.hasOwnProperty( 'requestAnimationFrame' ) ) { | |
| 1717 | - document.documentElement.scrollTop = end; | |
| 1718 | - return; | |
| 1719 | - } | |
| 1720 | - | |
| 1721 | - /* eslint-disable compat/compat */ | |
| 1722 | - const startTime = performance.now(); | |
| 1723 | - const step = currentTime => { | |
| 1724 | - const progress = Math.min( ( currentTime - startTime ) / duration, 1 ); | |
| 1725 | - document.documentElement.scrollTop = start + ( ( end - start ) * progress ); | |
| 1726 | - if ( progress < 1 ) { | |
| 1727 | - requestAnimationFrame( step ); | |
| 1728 | - } | |
| 1729 | - }; | |
| 1730 | - requestAnimationFrame( step ); | |
| 1731 | - /* eslint-enable compat/compat */ | |
| 1732 | - } | |
| 1733 | - | |
| 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 | - return { | |
| 1759 | - init: function() { | |
| 1760 | - jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); | |
| 1761 | - jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm ); | |
| 1762 | - | |
| 1763 | 1156 | 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 ); |
| 1157 | + jQuery( document ).on( 'change keyup', '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea', maybeShowLabel ); | |
| 1764 | 1158 | |
| 1765 | - jQuery( document ).on( 'change', '.frm_verify[id^=field_]', onHoneypotFieldChange ); | |
| 1159 | + jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange ); | |
| 1766 | 1160 | |
| 1767 | 1161 | jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick ); |
| 1162 | + jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv ); | |
| 1768 | 1163 | |
| 1769 | 1164 | checkForErrorsAndMaybeSetFocus(); |
| 1770 | 1165 | |
| 1771 | 1166 | // Focus on the first sub field when clicking to the primary label of combo field. |
| @@ -1770,79 +1165,53 @@ | ||
| 1770 | 1165 | |
| 1771 | 1166 | // Focus on the first sub field when clicking to the primary label of combo field. |
| 1772 | 1167 | changeFocusWhenClickComboFieldLabel(); |
| 1773 | 1168 | |
| 1774 | - initFloatingLabels(); | |
| 1775 | - maybeShowNewTabFallbackMessage(); | |
| 1169 | + // Add fallbacks for the beloved IE8 | |
| 1170 | + addIndexOfFallbackForIE8(); | |
| 1171 | + addTrimFallbackForIE8(); | |
| 1172 | + addFilterFallbackForIE8(); | |
| 1173 | + addKeysFallbackForIE8(); | |
| 1174 | + }, | |
| 1776 | 1175 | |
| 1777 | - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage ); | |
| 1778 | - setCustomValidityMessage(); | |
| 1779 | - jQuery( document ).on( 'frmFieldChanged', maybeClearCustomValidityMessage ); | |
| 1780 | - | |
| 1781 | - setSelectPlaceholderColor(); | |
| 1782 | - | |
| 1783 | - // Elementor popup show event. Fix Elementor Popup && FF Captcha field conflicts | |
| 1784 | - jQuery( document ).on( 'elementor/popup/show', frmRecaptcha ); | |
| 1785 | - | |
| 1786 | - enableSubmitButtonOnBackButtonPress(); | |
| 1787 | - jQuery( document ).on( | |
| 1788 | - 'frmPageChanged', | |
| 1789 | - destroyhCaptcha | |
| 1790 | - ); | |
| 1176 | + getFieldId: function( field, fullID ) { | |
| 1177 | + return getFieldId( field, fullID ); | |
| 1791 | 1178 | }, |
| 1792 | 1179 | |
| 1793 | - getFieldId, | |
| 1180 | + renderRecaptcha: function( captcha ) { | |
| 1181 | + var formID, recaptchaID, | |
| 1182 | + size = captcha.getAttribute( 'data-size' ), | |
| 1183 | + rendered = captcha.getAttribute( 'data-rid' ) !== null, | |
| 1184 | + params = { | |
| 1185 | + 'sitekey': captcha.getAttribute( 'data-sitekey' ), | |
| 1186 | + 'size': size, | |
| 1187 | + 'theme': captcha.getAttribute( 'data-theme' ) | |
| 1188 | + }; | |
| 1794 | 1189 | |
| 1795 | - /** | |
| 1796 | - * Render a captcha field. | |
| 1797 | - * | |
| 1798 | - * @param {HTMLElement} captcha | |
| 1799 | - * @param {string} captchaSelector | |
| 1800 | - * @return {void} | |
| 1801 | - */ | |
| 1802 | - renderCaptcha: function( captcha, captchaSelector ) { | |
| 1803 | - const rendered = captcha.getAttribute( 'data-rid' ) !== null; | |
| 1804 | 1190 | if ( rendered ) { |
| 1805 | 1191 | return; |
| 1806 | 1192 | } |
| 1807 | 1193 | |
| 1808 | - const size = captcha.getAttribute( 'data-size' ); | |
| 1809 | - const params = { | |
| 1810 | - sitekey: captcha.getAttribute( 'data-sitekey' ), | |
| 1811 | - size: size, | |
| 1812 | - theme: captcha.getAttribute( 'data-theme' ) | |
| 1813 | - }; | |
| 1814 | - | |
| 1815 | 1194 | if ( size === 'invisible' ) { |
| 1816 | - const formID = captcha.closest( 'form' )?.querySelector( 'input[name="form_id"]' )?.value; | |
| 1817 | - | |
| 1818 | - const captchaLabel = captcha.closest( '.frm_form_field' )?.querySelector( '.frm_primary_label' ); | |
| 1819 | - if ( captchaLabel ) { | |
| 1820 | - captchaLabel.style.display = 'none'; | |
| 1821 | - } | |
| 1822 | - | |
| 1195 | + formID = jQuery( captcha ).closest( 'form' ).find( 'input[name="form_id"]' ).val(); | |
| 1196 | + jQuery( captcha ).closest( '.frm_form_field .frm_primary_label' ).hide(); | |
| 1823 | 1197 | params.callback = function( token ) { |
| 1824 | 1198 | frmFrontForm.afterRecaptcha( token, formID ); |
| 1825 | 1199 | }; |
| 1826 | 1200 | } |
| 1827 | 1201 | |
| 1828 | - const activeCaptcha = getSelectedCaptcha( captchaSelector ); | |
| 1829 | - const captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? '#' + captcha.id : captcha.id; | |
| 1830 | - const captchaID = activeCaptcha.render( captchaContainer, params ); | |
| 1202 | + recaptchaID = grecaptcha.render( captcha.id, params ); | |
| 1831 | 1203 | |
| 1832 | - captcha.setAttribute( 'data-rid', captchaID ); | |
| 1833 | - | |
| 1834 | - maybeFixCaptchaLabel( captcha ); | |
| 1204 | + captcha.setAttribute( 'data-rid', recaptchaID ); | |
| 1835 | 1205 | }, |
| 1836 | 1206 | |
| 1837 | 1207 | afterSingleRecaptcha: function() { |
| 1838 | - const recaptcha = document.querySelector( '.frm-show-form .g-recaptcha' ); | |
| 1839 | - const object = recaptcha ? recaptcha.closest( 'form' ) : null; | |
| 1208 | + var object = jQuery( '.frm-show-form .g-recaptcha' ).closest( 'form' )[0]; | |
| 1840 | 1209 | frmFrontForm.submitFormNow( object ); |
| 1841 | 1210 | }, |
| 1842 | 1211 | |
| 1843 | - afterRecaptcha: function( _, formID ) { | |
| 1844 | - const object = document.querySelector( '#frm_form_' + formID + '_container form' ); | |
| 1212 | + afterRecaptcha: function( token, formID ) { | |
| 1213 | + var object = jQuery( '#frm_form_' + formID + '_container form' )[0]; | |
| 1845 | 1214 | frmFrontForm.submitFormNow( object ); |
| 1846 | 1215 | }, |
| 1847 | 1216 | |
| 1848 | 1217 | submitForm: function( e ) { |
| @@ -1848,43 +1217,49 @@ | ||
| 1848 | 1217 | submitForm: function( e ) { |
| 1849 | 1218 | frmFrontForm.submitFormManual( e, this ); |
| 1850 | 1219 | }, |
| 1851 | 1220 | |
| 1852 | - /** | |
| 1853 | - * @param {Event} e | |
| 1854 | - * @param {HTMLElement} object The form object that is being submitted. | |
| 1855 | - * @return {void} | |
| 1856 | - */ | |
| 1857 | 1221 | submitFormManual: function( e, object ) { |
| 1858 | - if ( document.body.classList.contains( 'wp-admin' ) && ! object.closest( '.frmapi-form' ) ) { | |
| 1222 | + var isPro, errors, | |
| 1223 | + invisibleRecaptcha = hasInvisibleRecaptcha( object ), | |
| 1224 | + classList = object.className.trim().split( /\s+/gi ); | |
| 1225 | + | |
| 1226 | + if ( classList && invisibleRecaptcha.length < 1 ) { | |
| 1227 | + isPro = classList.indexOf( 'frm_pro_form' ) > -1; | |
| 1228 | + if ( ! isPro ) { | |
| 1229 | + return; | |
| 1230 | + } | |
| 1231 | + } | |
| 1232 | + | |
| 1233 | + if ( jQuery( 'body' ).hasClass( 'wp-admin' ) && jQuery( object ).closest( '.frmapi-form' ).length < 1 ) { | |
| 1859 | 1234 | return; |
| 1860 | 1235 | } |
| 1861 | 1236 | |
| 1862 | 1237 | e.preventDefault(); |
| 1863 | 1238 | |
| 1864 | - if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' && ! frmProForm.submitAllowed( object ) ) { | |
| 1865 | - return; | |
| 1239 | + if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' ) { | |
| 1240 | + if ( ! frmProForm.submitAllowed( object ) ) { | |
| 1241 | + return; | |
| 1242 | + } | |
| 1866 | 1243 | } |
| 1867 | 1244 | |
| 1868 | - const errors = frmFrontForm.validateFormSubmit( object ); | |
| 1869 | - if ( Object.keys( errors ).length !== 0 ) { | |
| 1870 | - return; | |
| 1871 | - } | |
| 1872 | - | |
| 1873 | - const invisibleRecaptcha = hasInvisibleRecaptcha( object ); | |
| 1874 | - | |
| 1875 | - if ( invisibleRecaptcha ) { | |
| 1245 | + if ( invisibleRecaptcha.length ) { | |
| 1876 | 1246 | showLoadingIndicator( jQuery( object ) ); |
| 1877 | 1247 | executeInvisibleRecaptcha( invisibleRecaptcha ); |
| 1878 | 1248 | } else { |
| 1879 | - showSubmitLoading( jQuery( object ) ); | |
| 1880 | 1249 | |
| 1881 | - frmFrontForm.submitFormNow( object ); | |
| 1250 | + errors = frmFrontForm.validateFormSubmit( object ); | |
| 1251 | + | |
| 1252 | + if ( Object.keys( errors ).length === 0 ) { | |
| 1253 | + showSubmitLoading( jQuery( object ) ); | |
| 1254 | + | |
| 1255 | + frmFrontForm.submitFormNow( object, classList ); | |
| 1256 | + } | |
| 1882 | 1257 | } |
| 1883 | 1258 | }, |
| 1884 | 1259 | |
| 1885 | 1260 | submitFormNow: function( object ) { |
| 1886 | - let hasFileFields, antispamInput, | |
| 1261 | + var hasFileFields, antispamInput, | |
| 1887 | 1262 | classList = object.className.trim().split( /\s+/gi ); |
| 1888 | 1263 | |
| 1889 | 1264 | if ( object.hasAttribute( 'data-token' ) && null === object.querySelector( '[name="antispam_token"]' ) ) { |
| 1890 | 1265 | // include the antispam token on form submit. |
| @@ -1891,24 +1266,17 @@ | ||
| 1891 | 1266 | antispamInput = document.createElement( 'input' ); |
| 1892 | 1267 | antispamInput.type = 'hidden'; |
| 1893 | 1268 | antispamInput.name = 'antispam_token'; |
| 1894 | 1269 | antispamInput.value = object.getAttribute( 'data-token' ); |
| 1895 | - object.append( antispamInput ); | |
| 1270 | + object.appendChild( antispamInput ); | |
| 1896 | 1271 | } |
| 1897 | 1272 | |
| 1898 | - // Add a unique ID, used for duplicate checks. | |
| 1899 | - const uniqueIDInput = document.createElement( 'input' ); | |
| 1900 | - uniqueIDInput.type = 'hidden'; | |
| 1901 | - uniqueIDInput.name = 'unique_id'; | |
| 1902 | - uniqueIDInput.value = getUniqueKey(); | |
| 1903 | - object.append( uniqueIDInput ); | |
| 1904 | - | |
| 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; | |
| 1273 | + if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) { | |
| 1274 | + hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() { | |
| 1275 | + return !! this.value; | |
| 1276 | + }).length; | |
| 1908 | 1277 | if ( hasFileFields < 1 ) { |
| 1909 | - const actionInput = object.querySelector( 'input[name="frm_action"]' ); | |
| 1910 | - const action = actionInput ? actionInput.value : ''; | |
| 1278 | + action = jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 1911 | 1279 | frmFrontForm.checkFormErrors( object, action ); |
| 1912 | 1280 | } else { |
| 1913 | 1281 | object.submit(); |
| 1914 | 1282 | } |
| @@ -1916,16 +1284,10 @@ | ||
| 1916 | 1284 | object.submit(); |
| 1917 | 1285 | } |
| 1918 | 1286 | }, |
| 1919 | 1287 | |
| 1920 | - /** | |
| 1921 | - * @param {HTMLElement|Object} object Form object. This might be a jQuery object. | |
| 1922 | - * | |
| 1923 | - * @return {Array} List of errors. | |
| 1924 | - */ | |
| 1925 | 1288 | validateFormSubmit: function( object ) { |
| 1926 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1927 | - if ( typeof tinyMCE !== 'undefined' && form && form.querySelector( '.wp-editor-wrap' ) ) { | |
| 1289 | + if ( typeof tinyMCE !== 'undefined' && jQuery( object ).find( '.wp-editor-wrap' ).length ) { | |
| 1928 | 1290 | tinyMCE.triggerSave(); |
| 1929 | 1291 | } |
| 1930 | 1292 | |
| 1931 | 1293 | jsErrors = []; |
| @@ -1940,22 +1302,16 @@ | ||
| 1940 | 1302 | |
| 1941 | 1303 | return jsErrors; |
| 1942 | 1304 | }, |
| 1943 | 1305 | |
| 1944 | - /** | |
| 1945 | - * @param {HTMLElement|Object} object Form object. This might be a jQuery object. | |
| 1946 | - * @return {Array} List of errors. | |
| 1947 | - */ | |
| 1948 | 1306 | getAjaxFormErrors: function( object ) { |
| 1949 | - let customErrors, key; | |
| 1950 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1307 | + var customErrors, key; | |
| 1951 | 1308 | |
| 1952 | 1309 | jsErrors = validateForm( object ); |
| 1953 | 1310 | 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 : ''; | |
| 1311 | + action = jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 1956 | 1312 | customErrors = frmThemeOverride_jsErrors( action, object ); |
| 1957 | - if ( Object.keys( customErrors ).length ) { | |
| 1313 | + if ( Object.keys( customErrors ).length ) { | |
| 1958 | 1314 | for ( key in customErrors ) { |
| 1959 | 1315 | jsErrors[ key ] = customErrors[ key ]; |
| 1960 | 1316 | } |
| 1961 | 1317 | } |
| @@ -1960,30 +1316,20 @@ | ||
| 1960 | 1316 | } |
| 1961 | 1317 | } |
| 1962 | 1318 | } |
| 1963 | 1319 | |
| 1964 | - triggerCustomEvent( document, 'frm_get_ajax_form_errors', { | |
| 1965 | - formEl: object, | |
| 1966 | - errors: jsErrors | |
| 1967 | - } ); | |
| 1968 | - | |
| 1969 | 1320 | return jsErrors; |
| 1970 | 1321 | }, |
| 1971 | 1322 | |
| 1972 | - /** | |
| 1973 | - * @param {HTMLElement|Object} object Form object. This might be a jQuery object. | |
| 1974 | - * @return {void} | |
| 1975 | - */ | |
| 1976 | 1323 | addAjaxFormErrors: function( object ) { |
| 1977 | - let key; | |
| 1978 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1324 | + var key, $fieldCont; | |
| 1979 | 1325 | removeAllErrors(); |
| 1980 | 1326 | |
| 1981 | 1327 | for ( key in jsErrors ) { |
| 1982 | - const fieldCont = form ? form.querySelector( '#frm_field_' + key + '_container' ) : null; | |
| 1328 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 1983 | 1329 | |
| 1984 | - if ( fieldCont ) { | |
| 1985 | - addFieldError( fieldCont, key, jsErrors ); | |
| 1330 | + if ( $fieldCont.length ) { | |
| 1331 | + addFieldError( $fieldCont, key, jsErrors ); | |
| 1986 | 1332 | } else { |
| 1987 | 1333 | // we are unable to show the error, so remove it |
| 1988 | 1334 | delete jsErrors[ key ]; |
| 1989 | 1335 | } |
| @@ -1992,20 +1338,31 @@ | ||
| 1992 | 1338 | scrollToFirstField( object ); |
| 1993 | 1339 | checkForErrorsAndMaybeSetFocus(); |
| 1994 | 1340 | }, |
| 1995 | 1341 | |
| 1996 | - checkFormErrors: getFormErrors, | |
| 1997 | - checkRequiredField, | |
| 1998 | - showSubmitLoading, | |
| 1999 | - removeSubmitLoading, | |
| 1342 | + checkFormErrors: function( object, action ) { | |
| 1343 | + getFormErrors( object, action ); | |
| 1344 | + }, | |
| 2000 | 1345 | |
| 2001 | - scrollToID: function( id ) { | |
| 2002 | - const object = jQuery( document.getElementById( id ) ); | |
| 2003 | - frmFrontForm.scrollMsg( object, false ); | |
| 1346 | + checkRequiredField: function( field, errors ) { | |
| 1347 | + return checkRequiredField( field, errors ); | |
| 2004 | 1348 | }, |
| 2005 | 1349 | |
| 1350 | + showSubmitLoading: function( $object ) { | |
| 1351 | + showSubmitLoading( $object ); | |
| 1352 | + }, | |
| 1353 | + | |
| 1354 | + removeSubmitLoading: function( $object, enable, processesRunning ) { | |
| 1355 | + removeSubmitLoading( $object, enable, processesRunning ); | |
| 1356 | + }, | |
| 1357 | + | |
| 1358 | + scrollToID: function( id ) { | |
| 1359 | + var object = jQuery( document.getElementById( id ) ); | |
| 1360 | + frmFrontForm.scrollMsg( object, false ); | |
| 1361 | + }, | |
| 1362 | + | |
| 2006 | 1363 | scrollMsg: function( id, object, animate ) { |
| 2007 | - let newPos, m, b, screenTop, screenBottom, | |
| 1364 | + var newPos, m, b, screenTop, screenBottom, | |
| 2008 | 1365 | scrollObj = ''; |
| 2009 | 1366 | if ( typeof object === 'undefined' ) { |
| 2010 | 1367 | scrollObj = jQuery( document.getElementById( 'frm_form_' + id + '_container' ) ); |
| 2011 | 1368 | if ( scrollObj.length < 1 ) { |
| @@ -2011,11 +1368,9 @@ | ||
| 2011 | 1368 | if ( scrollObj.length < 1 ) { |
| 2012 | 1369 | return; |
| 2013 | 1370 | } |
| 2014 | 1371 | } 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(); | |
| 1372 | + scrollObj = jQuery( object ).find( '#frm_field_' + id + '_container' ); | |
| 2018 | 1373 | } else { |
| 2019 | 1374 | scrollObj = id; |
| 2020 | 1375 | } |
| 2021 | 1376 | |
| @@ -2020,15 +1375,15 @@ | ||
| 2020 | 1375 | } |
| 2021 | 1376 | |
| 2022 | 1377 | jQuery( scrollObj ).trigger( 'focus' ); |
| 2023 | 1378 | newPos = scrollObj.offset().top; |
| 2024 | - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase | |
| 1379 | + if ( ! newPos || frm_js.offset === '-1' ) { | |
| 2025 | 1380 | return; |
| 2026 | 1381 | } |
| 2027 | - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase | |
| 1382 | + newPos = newPos - frm_js.offset; | |
| 2028 | 1383 | |
| 2029 | - m = getComputedStyle( document.documentElement ).marginTop; | |
| 2030 | - b = getComputedStyle( document.body ).marginTop; | |
| 1384 | + m = jQuery( 'html' ).css( 'margin-top' ); | |
| 1385 | + b = jQuery( 'body' ).css( 'margin-top' ); | |
| 2031 | 1386 | if ( m || b ) { |
| 2032 | 1387 | newPos = newPos - parseInt( m ) - parseInt( b ); |
| 2033 | 1388 | } |
| 2034 | 1389 | |
| @@ -2038,11 +1393,11 @@ | ||
| 2038 | 1393 | |
| 2039 | 1394 | if ( newPos > screenBottom || newPos < screenTop ) { |
| 2040 | 1395 | // Not in view |
| 2041 | 1396 | if ( typeof animate === 'undefined' ) { |
| 2042 | - document.documentElement.scrollTop = newPos; | |
| 1397 | + jQuery( window ).scrollTop( newPos ); | |
| 2043 | 1398 | } else { |
| 2044 | - animateScroll( screenTop, newPos, 500 ); | |
| 1399 | + jQuery( 'html,body' ).animate({ scrollTop: newPos }, 500 ); | |
| 2045 | 1400 | } |
| 2046 | 1401 | return false; |
| 2047 | 1402 | } |
| 2048 | 1403 | } |
| @@ -2050,10 +1405,10 @@ | ||
| 2050 | 1405 | |
| 2051 | 1406 | fieldValueChanged: function( e ) { |
| 2052 | 1407 | /*jshint validthis:true */ |
| 2053 | 1408 | |
| 2054 | - const fieldId = frmFrontForm.getFieldId( this, false ); | |
| 2055 | - if ( ! fieldId ) { | |
| 1409 | + var fieldId = frmFrontForm.getFieldId( this, false ); | |
| 1410 | + if ( ! fieldId || typeof fieldId === 'undefined' ) { | |
| 2056 | 1411 | return; |
| 2057 | 1412 | } |
| 2058 | 1413 | |
| 2059 | 1414 | if ( e.frmTriggered && e.frmTriggered == fieldId ) { |
| @@ -2059,9 +1414,9 @@ | ||
| 2059 | 1414 | if ( e.frmTriggered && e.frmTriggered == fieldId ) { |
| 2060 | 1415 | return; |
| 2061 | 1416 | } |
| 2062 | 1417 | |
| 2063 | - jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ] ); | |
| 1418 | + jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]); | |
| 2064 | 1419 | |
| 2065 | 1420 | if ( e.selfTriggered !== true ) { |
| 2066 | 1421 | maybeValidateChange( this ); |
| 2067 | 1422 | } |
| @@ -2066,10 +1421,56 @@ | ||
| 2066 | 1421 | maybeValidateChange( this ); |
| 2067 | 1422 | } |
| 2068 | 1423 | }, |
| 2069 | 1424 | |
| 1425 | + savingDraft: function( object ) { | |
| 1426 | + console.warn( 'DEPRECATED: function frmFrontForm.savingDraft in v3.0 use frmProForm.savingDraft' ); | |
| 1427 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1428 | + return frmProForm.savingDraft( object ); | |
| 1429 | + } | |
| 1430 | + }, | |
| 1431 | + | |
| 1432 | + goingToPreviousPage: function( object ) { | |
| 1433 | + console.warn( 'DEPRECATED: function frmFrontForm.goingToPreviousPage in v3.0 use frmProForm.goingToPreviousPage' ); | |
| 1434 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1435 | + return frmProForm.goingToPreviousPage( object ); | |
| 1436 | + } | |
| 1437 | + }, | |
| 1438 | + | |
| 1439 | + hideOrShowFields: function() { | |
| 1440 | + console.warn( 'DEPRECATED: function frmFrontForm.hideOrShowFields in v3.0 use frmProForm.hideOrShowFields' ); | |
| 1441 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1442 | + frmProForm.hideOrShowFields(); | |
| 1443 | + } | |
| 1444 | + }, | |
| 1445 | + | |
| 1446 | + hidePreviouslyHiddenFields: function() { | |
| 1447 | + console.warn( 'DEPRECATED: function frmFrontForm.hidePreviouslyHiddenFields in v3.0 use frmProForm.hidePreviouslyHiddenFields' ); | |
| 1448 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1449 | + frmProForm.hidePreviouslyHiddenFields(); | |
| 1450 | + } | |
| 1451 | + }, | |
| 1452 | + | |
| 1453 | + checkDependentDynamicFields: function( ids ) { | |
| 1454 | + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentDynamicFields in v3.0 use frmProForm.checkDependentDynamicFields' ); | |
| 1455 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1456 | + frmProForm.checkDependentDynamicFields( ids ); | |
| 1457 | + } | |
| 1458 | + }, | |
| 1459 | + | |
| 1460 | + checkDependentLookupFields: function( ids ) { | |
| 1461 | + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentLookupFields in v3.0 use frmProForm.checkDependentLookupFields' ); | |
| 1462 | + if ( typeof frmProForm !== 'undefined' ) { | |
| 1463 | + frmProForm.checkDependentLookupFields( ids ); | |
| 1464 | + } | |
| 1465 | + }, | |
| 1466 | + | |
| 1467 | + loadGoogle: function() { | |
| 1468 | + console.warn( 'DEPRECATED: function frmFrontForm.loadGoogle in v3.0 use frmProForm.loadGoogle' ); | |
| 1469 | + frmProForm.loadGoogle(); | |
| 1470 | + }, | |
| 1471 | + | |
| 2070 | 1472 | escapeHtml: function( text ) { |
| 2071 | - console.warn( 'DEPRECATED: function frmFrontForm.escapeHtml in v6.17' ); | |
| 2072 | 1473 | return text |
| 2073 | 1474 | .replace( /&/g, '&' ) |
| 2074 | 1475 | .replace( /</g, '<' ) |
| 2075 | 1476 | .replace( />/g, '>' ) |
| @@ -2076,82 +1477,97 @@ | ||
| 2076 | 1477 | .replace( /"/g, '"' ) |
| 2077 | 1478 | .replace( /'/g, ''' ); |
| 2078 | 1479 | }, |
| 2079 | 1480 | |
| 2080 | - triggerCustomEvent: triggerCustomEvent, | |
| 2081 | - documentOn | |
| 1481 | + invisible: function( classes ) { | |
| 1482 | + jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 1483 | + }, | |
| 1484 | + | |
| 1485 | + visible: function( classes ) { | |
| 1486 | + jQuery( classes ).css( 'visibility', 'visible' ); | |
| 1487 | + } | |
| 2082 | 1488 | }; |
| 2083 | 1489 | } |
| 1490 | +frmFrontForm = frmFrontFormJS(); | |
| 2084 | 1491 | |
| 2085 | -window.frmFrontForm = frmFrontFormJS(); | |
| 2086 | - | |
| 2087 | 1492 | jQuery( document ).ready( function() { |
| 2088 | 1493 | frmFrontForm.init(); |
| 2089 | -} ); | |
| 1494 | +}); | |
| 2090 | 1495 | |
| 2091 | 1496 | function frmRecaptcha() { |
| 2092 | - frmCaptcha( '.frm-g-recaptcha' ); | |
| 1497 | + var c, cl, | |
| 1498 | + captchas = jQuery( '.frm-g-recaptcha' ); | |
| 1499 | + for ( c = 0, cl = captchas.length; c < cl; c++ ) { | |
| 1500 | + frmFrontForm.renderRecaptcha( captchas[c]); | |
| 1501 | + } | |
| 2093 | 1502 | } |
| 2094 | 1503 | |
| 2095 | -function frmHcaptcha() { | |
| 2096 | - frmCaptcha( '.h-captcha' ); | |
| 1504 | +function frmAfterRecaptcha( token ) { | |
| 1505 | + frmFrontForm.afterSingleRecaptcha( token ); | |
| 2097 | 1506 | } |
| 2098 | 1507 | |
| 2099 | -function frmTurnstile() { | |
| 2100 | - frmCaptcha( '.frm-cf-turnstile' ); | |
| 1508 | +function frmUpdateField( entryId, fieldId, value, message, num ) { | |
| 1509 | + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' ); | |
| 1510 | + jQuery.ajax({ | |
| 1511 | + type: 'POST', | |
| 1512 | + url: frm_js.ajax_url, | |
| 1513 | + data: { | |
| 1514 | + action: 'frm_entries_update_field_ajax', | |
| 1515 | + entry_id: entryId, | |
| 1516 | + field_id: fieldId, | |
| 1517 | + value: value, | |
| 1518 | + nonce: frm_js.nonce | |
| 1519 | + }, | |
| 1520 | + success: function() { | |
| 1521 | + if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) { | |
| 1522 | + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' ); | |
| 1523 | + } else { | |
| 1524 | + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).replaceWith( message ); | |
| 1525 | + } | |
| 1526 | + } | |
| 1527 | + }); | |
| 2101 | 1528 | } |
| 2102 | 1529 | |
| 2103 | -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 | - } ); | |
| 1530 | +function frmDeleteEntry( entryId, prefix ) { | |
| 1531 | + console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' ); | |
| 1532 | + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' ); | |
| 1533 | + jQuery.ajax({ | |
| 1534 | + type: 'POST', | |
| 1535 | + url: frm_js.ajax_url, | |
| 1536 | + data: { | |
| 1537 | + action: 'frm_entries_destroy', | |
| 1538 | + entry: entryId, | |
| 1539 | + nonce: frm_js.nonce | |
| 1540 | + }, | |
| 1541 | + success: function( html ) { | |
| 1542 | + if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) { | |
| 1543 | + jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' ); | |
| 1544 | + } else { | |
| 1545 | + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( html ); | |
| 1546 | + } | |
| 2115 | 1547 | } |
| 2116 | - return; | |
| 2117 | - } | |
| 2118 | - | |
| 2119 | - let c; | |
| 2120 | - const captchas = document.querySelectorAll( captchaSelector ); | |
| 2121 | - const cl = captchas.length; | |
| 2122 | - for ( c = 0; c < cl; c++ ) { | |
| 2123 | - const closestForm = captchas[ c ].closest( 'form' ); | |
| 2124 | - const formIsVisible = closestForm && closestForm.offsetParent !== null; | |
| 2125 | - const captcha = captchas[ c ]; | |
| 2126 | - if ( ! formIsVisible ) { | |
| 2127 | - // If the form is not visible, try again later in 400ms. | |
| 2128 | - // This fixes issues where the form fades visible on page load. | |
| 2129 | - // Or whne the form is inside of a modal. | |
| 2130 | - const interval = setInterval( | |
| 2131 | - function() { | |
| 2132 | - if ( closestForm && closestForm.offsetParent !== null ) { | |
| 2133 | - frmFrontForm.renderCaptcha( captcha, captchaSelector ); | |
| 2134 | - clearInterval( interval ); | |
| 2135 | - } | |
| 2136 | - }, | |
| 2137 | - 400 | |
| 2138 | - ); | |
| 2139 | - continue; | |
| 2140 | - } | |
| 2141 | - frmFrontForm.renderCaptcha( captcha, captchaSelector ); | |
| 2142 | - } | |
| 1548 | + }); | |
| 2143 | 1549 | } |
| 2144 | 1550 | |
| 2145 | -function getSelectedCaptcha( captchaSelector ) { | |
| 2146 | - if ( captchaSelector === '.frm-g-recaptcha' ) { | |
| 2147 | - return grecaptcha; | |
| 2148 | - } | |
| 2149 | - if ( document.querySelector( '.frm-cf-turnstile' ) ) { | |
| 2150 | - return turnstile; | |
| 2151 | - } | |
| 2152 | - return hcaptcha; | |
| 1551 | +function frmOnSubmit( e ) { | |
| 1552 | + console.warn( 'DEPRECATED: function frmOnSubmit in v2.0 use frmFrontForm.submitForm' ); | |
| 1553 | + frmFrontForm.submitForm( e, this ); | |
| 2153 | 1554 | } |
| 2154 | 1555 | |
| 2155 | -function frmAfterRecaptcha( token ) { | |
| 2156 | - frmFrontForm.afterSingleRecaptcha( token ); | |
| 1556 | +function frm_resend_email( entryId, formId ) { // eslint-disable-line camelcase | |
| 1557 | + var $link = jQuery( document.getElementById( 'frm_resend_email' ) ); | |
| 1558 | + console.warn( 'DEPRECATED: function frm_resend_email in v2.0' ); | |
| 1559 | + $link.append( '<span class="spinner" style="display:inline"></span>' ); | |
| 1560 | + jQuery.ajax({ | |
| 1561 | + type: 'POST', | |
| 1562 | + url: frm_js.ajax_url, | |
| 1563 | + data: { | |
| 1564 | + action: 'frm_entries_send_email', | |
| 1565 | + entry_id: entryId, | |
| 1566 | + form_id: formId, | |
| 1567 | + nonce: frm_js.nonce | |
| 1568 | + }, | |
| 1569 | + success: function( msg ) { | |
| 1570 | + $link.replaceWith( msg ); | |
| 1571 | + } | |
| 1572 | + }); | |
| 2157 | 1573 | } |