| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | |
| 7 | 7 | /*global jQuery:false, frm_js, grecaptcha, hcaptcha, turnstile, frmProForm, tinyMCE */ |
| 8 | 8 | /*global frmThemeOverride_jsErrors, frmThemeOverride_frmPlaceError, frmThemeOverride_frmAfterSubmit */ |
| 9 | 9 | |
| 10 | + let action = ''; | |
| 10 | 11 | let jsErrors = []; |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Triggers custom JS event. |
| @@ -15,9 +16,9 @@ | ||
| 15 | 16 | * @since 5.5.3 |
| 16 | 17 | * |
| 17 | 18 | * @param {HTMLElement} el The HTML element. |
| 18 | 19 | * @param {string} eventName Event name. |
| 19 | - * @param {*} data The passed data. | |
| 20 | + * @param {mixed} data The passed data. | |
| 20 | 21 | */ |
| 21 | 22 | function triggerCustomEvent( el, eventName, data ) { |
| 22 | 23 | if ( typeof window.CustomEvent !== 'function' ) { |
| 23 | 24 | return; |
| @@ -28,32 +29,29 @@ | ||
| 28 | 29 | |
| 29 | 30 | el.dispatchEvent( event ); |
| 30 | 31 | } |
| 31 | 32 | |
| 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 | - */ | |
| 33 | + /* Get the ID of the field that changed*/ | |
| 39 | 34 | function getFieldId( field, fullID ) { |
| 40 | 35 | let nameParts, fieldId, |
| 41 | 36 | isRepeating = false, |
| 42 | 37 | fieldName = ''; |
| 43 | - | |
| 44 | 38 | if ( field instanceof jQuery ) { |
| 45 | - field = field.get( 0 ); | |
| 39 | + fieldName = field.attr( 'name' ); | |
| 40 | + } else { | |
| 41 | + fieldName = field.name; | |
| 46 | 42 | } |
| 47 | 43 | |
| 48 | - fieldName = field.name; | |
| 49 | - | |
| 50 | 44 | if ( typeof fieldName === 'undefined' ) { |
| 51 | 45 | fieldName = ''; |
| 52 | 46 | } |
| 53 | 47 | |
| 54 | 48 | if ( fieldName === '' ) { |
| 55 | - fieldName = field.getAttribute( 'data-name' ); | |
| 49 | + if ( field instanceof jQuery ) { | |
| 50 | + fieldName = field.data( 'name' ); | |
| 51 | + } else { | |
| 52 | + fieldName = field.getAttribute( 'data-name' ); | |
| 53 | + } | |
| 56 | 54 | |
| 57 | 55 | if ( typeof fieldName === 'undefined' ) { |
| 58 | 56 | fieldName = ''; |
| 59 | 57 | } |
| @@ -70,24 +68,25 @@ | ||
| 70 | 68 | return 0; |
| 71 | 69 | } |
| 72 | 70 | nameParts = nameParts.filter( function( n ) { |
| 73 | 71 | return n !== ''; |
| 74 | - } ); | |
| 72 | + }); | |
| 75 | 73 | |
| 76 | - fieldId = nameParts[ 0 ]; | |
| 74 | + fieldId = nameParts[0]; | |
| 77 | 75 | |
| 78 | 76 | if ( nameParts.length === 1 ) { |
| 79 | 77 | return fieldId; |
| 80 | 78 | } |
| 81 | 79 | |
| 82 | - if ( nameParts[ 1 ] === '[form' || nameParts[ 1 ] === '[row_ids' ) { | |
| 80 | + if ( nameParts[1] === '[form' || nameParts[1] === '[row_ids' ) { | |
| 83 | 81 | return 0; |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | 84 | // Check if 'this' is in a repeating section |
| 87 | - if ( document.querySelector( 'input[name="item_meta[' + fieldId + '][form]"]' ) ) { | |
| 85 | + if ( jQuery( 'input[name="item_meta[' + fieldId + '][form]"]' ).length ) { | |
| 86 | + | |
| 88 | 87 | // this is a repeatable section with name: item_meta[repeating-section-id][row-id][field-id] |
| 89 | - fieldId = nameParts[ 2 ].replace( '[', '' ); | |
| 88 | + fieldId = nameParts[2].replace( '[', '' ); | |
| 90 | 89 | isRepeating = true; |
| 91 | 90 | } |
| 92 | 91 | |
| 93 | 92 | // Check if 'this' is an other text field and get field ID for it |
| @@ -93,21 +92,21 @@ | ||
| 93 | 92 | // Check if 'this' is an other text field and get field ID for it |
| 94 | 93 | if ( 'other' === fieldId ) { |
| 95 | 94 | if ( isRepeating ) { |
| 96 | 95 | // name for other fields: item_meta[370][0][other][414] |
| 97 | - fieldId = nameParts[ 3 ].replace( '[', '' ); | |
| 96 | + fieldId = nameParts[3].replace( '[', '' ); | |
| 98 | 97 | } else { |
| 99 | 98 | // Other field name: item_meta[other][370] |
| 100 | - fieldId = nameParts[ 1 ].replace( '[', '' ); | |
| 99 | + fieldId = nameParts[1].replace( '[', '' ); | |
| 101 | 100 | } |
| 102 | 101 | } |
| 103 | 102 | |
| 104 | 103 | if ( fullID === true ) { |
| 105 | 104 | // For use in the container div id |
| 106 | - if ( fieldId === nameParts[ 0 ] ) { | |
| 107 | - fieldId = fieldId + '-' + nameParts[ 1 ].replace( '[', '' ); | |
| 105 | + if ( fieldId === nameParts[0]) { | |
| 106 | + fieldId = fieldId + '-' + nameParts[1].replace( '[', '' ); | |
| 108 | 107 | } else { |
| 109 | - fieldId = fieldId + '-' + nameParts[ 0 ] + '-' + nameParts[ 1 ].replace( '[', '' ); | |
| 108 | + fieldId = fieldId + '-' + nameParts[0] + '-' + nameParts[1].replace( '[', '' ); | |
| 110 | 109 | } |
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | return fieldId; |
| @@ -120,15 +119,9 @@ | ||
| 120 | 119 | * |
| 121 | 120 | * @param {Object} $form |
| 122 | 121 | */ |
| 123 | 122 | 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 | - ); | |
| 123 | + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"], button.frm_save_draft' ).attr( 'disabled', 'disabled' ); | |
| 131 | 124 | } |
| 132 | 125 | |
| 133 | 126 | /** |
| 134 | 127 | * Enable the submit button for a given jQuery form object |
| @@ -134,16 +127,12 @@ | ||
| 134 | 127 | * Enable the submit button for a given jQuery form object |
| 135 | 128 | * |
| 136 | 129 | * @since 2.03.02 |
| 137 | 130 | * |
| 138 | - * @param {HTMLElement} form | |
| 139 | - * | |
| 140 | - * @return {void} | |
| 131 | + * @param {Object} $form | |
| 141 | 132 | */ |
| 142 | - function enableSubmitButton( form ) { | |
| 143 | - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"]' ).forEach( | |
| 144 | - button => button.disabled = false | |
| 145 | - ); | |
| 133 | + function enableSubmitButton( $form ) { | |
| 134 | + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false ); | |
| 146 | 135 | } |
| 147 | 136 | |
| 148 | 137 | /** |
| 149 | 138 | * Disable the save draft link for a given jQuery form object |
| @@ -152,69 +141,51 @@ | ||
| 152 | 141 | * |
| 153 | 142 | * @param {Object} $form |
| 154 | 143 | */ |
| 155 | 144 | 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 | - ); | |
| 145 | + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', 'none' ); | |
| 163 | 146 | } |
| 164 | 147 | |
| 165 | 148 | /** |
| 166 | - * Enable the save draft link for a given form object. | |
| 149 | + * Enable the save draft link for a given jQuery form object | |
| 167 | 150 | * |
| 168 | 151 | * @since 4.04.03 |
| 169 | 152 | * |
| 170 | - * @param {jQuery|HTMLElement} $form | |
| 153 | + * @param {Object} $form | |
| 171 | 154 | */ |
| 172 | 155 | function enableSaveDraft( $form ) { |
| 173 | - const form = $form instanceof jQuery ? $form.get( 0 ) : $form; | |
| 174 | - if ( ! form ) { | |
| 156 | + if ( ! $form.length ) { | |
| 175 | 157 | return; |
| 176 | 158 | } |
| 177 | - form.querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => { | |
| 178 | - saveDraftButton.disabled = false; | |
| 159 | + $form[0].querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => { | |
| 160 | + saveDraftButton.disabled = false; | |
| 179 | 161 | saveDraftButton.style.pointerEvents = ''; |
| 180 | - } ); | |
| 162 | + }); | |
| 181 | 163 | } |
| 182 | 164 | |
| 183 | - /** | |
| 184 | - * Validate form with JS. | |
| 185 | - * | |
| 186 | - * @param {HTMLElement|jQuery} object | |
| 187 | - * @return {Array} Errors. | |
| 188 | - */ | |
| 189 | 165 | function validateForm( object ) { |
| 190 | - let errors = []; | |
| 166 | + let errors, r, rl, n, nl, fields, field, requiredFields; | |
| 191 | 167 | |
| 192 | - const vanillaJsObject = 'function' === typeof object.get ? object.get( 0 ) : object; | |
| 168 | + errors = []; | |
| 193 | 169 | |
| 194 | - // Required field validation. | |
| 195 | - vanillaJsObject?.querySelectorAll( '.frm_required_field' ).forEach( | |
| 196 | - requiredField => { | |
| 197 | - const isVisible = requiredField.offsetParent !== null; | |
| 198 | - if ( ! isVisible ) { | |
| 199 | - return; | |
| 170 | + // Make sure required text field is filled in | |
| 171 | + requiredFields = jQuery( object ).find( | |
| 172 | + '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea' | |
| 173 | + ).filter( ':not(.frm_optional)' ); | |
| 174 | + if ( requiredFields.length ) { | |
| 175 | + for ( r = 0, rl = requiredFields.length; r < rl; r++ ) { | |
| 176 | + if ( hasClass( requiredFields[r], 'ed_button' ) ) { | |
| 177 | + // skip rich text field buttons. | |
| 178 | + continue; | |
| 200 | 179 | } |
| 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 | - ); | |
| 180 | + errors = checkRequiredField( requiredFields[r], errors ); | |
| 212 | 181 | } |
| 213 | - ); | |
| 182 | + } | |
| 214 | 183 | |
| 215 | - vanillaJsObject?.querySelectorAll( 'input,select,textarea' ).forEach( | |
| 216 | - field => { | |
| 184 | + fields = jQuery( object ).find( 'input,select,textarea' ); | |
| 185 | + if ( fields.length ) { | |
| 186 | + for ( n = 0, nl = fields.length; n < nl; n++ ) { | |
| 187 | + field = fields[n]; | |
| 217 | 188 | if ( '' === field.value ) { |
| 218 | 189 | if ( 'number' === field.type ) { |
| 219 | 190 | // A number field will return an empty string when it is invalid. |
| 220 | 191 | checkValidity( field, errors ); |
| @@ -223,9 +194,9 @@ | ||
| 223 | 194 | const isConfirmationField = field.name && 0 === field.name.indexOf( 'item_meta[conf_' ); |
| 224 | 195 | if ( ! isConfirmationField ) { |
| 225 | 196 | // Allow a blank confirmation field to still call validateFieldValue. |
| 226 | 197 | // If we continue for a confirmation field there are issues with forms submitting with a blank confirmation field. |
| 227 | - return; | |
| 198 | + continue; | |
| 228 | 199 | } |
| 229 | 200 | } |
| 230 | 201 | |
| 231 | 202 | validateFieldValue( field, errors, true ); |
| @@ -230,9 +201,9 @@ | ||
| 230 | 201 | |
| 231 | 202 | validateFieldValue( field, errors, true ); |
| 232 | 203 | checkValidity( field, errors ); |
| 233 | 204 | } |
| 234 | - ); | |
| 205 | + } | |
| 235 | 206 | |
| 236 | 207 | // Invisible captchas are processed after validation. |
| 237 | 208 | // We only want to validate a visible captcha on submit. |
| 238 | 209 | if ( ! hasInvisibleRecaptcha( object ) ) { |
| @@ -256,9 +227,9 @@ | ||
| 256 | 227 | return; |
| 257 | 228 | } |
| 258 | 229 | |
| 259 | 230 | fieldID = getFieldId( field, true ); |
| 260 | - if ( 'undefined' === typeof errors[ fieldID ] ) { | |
| 231 | + if ( 'undefined' === typeof errors[ fieldID ]) { | |
| 261 | 232 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 262 | 233 | } |
| 263 | 234 | |
| 264 | 235 | if ( 'function' === typeof field.reportValidity ) { |
| @@ -277,51 +248,31 @@ | ||
| 277 | 248 | function hasClass( element, targetClass ) { |
| 278 | 249 | return element.classList && element.classList.contains( targetClass ); |
| 279 | 250 | } |
| 280 | 251 | |
| 281 | - /** | |
| 282 | - * @param {HTMLElement} field | |
| 283 | - */ | |
| 284 | 252 | function maybeValidateChange( field ) { |
| 285 | 253 | if ( field.type === 'url' ) { |
| 286 | - maybeAddHttpsToUrl( field ); | |
| 254 | + maybeAddHttpToUrl( field ); | |
| 287 | 255 | } |
| 288 | - const form = field.closest( 'form' ); | |
| 289 | - if ( form && hasClass( form, 'frm_js_validate' ) ) { | |
| 256 | + if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) { | |
| 290 | 257 | validateField( field ); |
| 291 | 258 | } |
| 292 | 259 | } |
| 293 | 260 | |
| 294 | - /** | |
| 295 | - * @param {HTMLElement} field | |
| 296 | - */ | |
| 297 | - function maybeAddHttpsToUrl( field ) { | |
| 261 | + function maybeAddHttpToUrl( field ) { | |
| 298 | 262 | const url = field.value; |
| 299 | 263 | const matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ ); |
| 300 | 264 | if ( field.value !== '' && matches === null ) { |
| 301 | - field.value = 'https://' + url; | |
| 265 | + field.value = 'http://' + url; | |
| 302 | 266 | } |
| 303 | 267 | } |
| 304 | 268 | |
| 305 | - /** | |
| 306 | - * Validate a field with JS. | |
| 307 | - * | |
| 308 | - * @param {HTMLElement} field | |
| 309 | - * | |
| 310 | - * @return {void} | |
| 311 | - */ | |
| 312 | 269 | function validateField( field ) { |
| 313 | - let errors, key; | |
| 270 | + let key, | |
| 271 | + errors = [], | |
| 272 | + $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 314 | 273 | |
| 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' ) ) { | |
| 274 | + if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) { | |
| 324 | 275 | errors = checkRequiredField( field, errors ); |
| 325 | 276 | } |
| 326 | 277 | |
| 327 | 278 | if ( errors.length < 1 ) { |
| @@ -327,12 +278,12 @@ | ||
| 327 | 278 | if ( errors.length < 1 ) { |
| 328 | 279 | validateFieldValue( field, errors, false ); |
| 329 | 280 | } |
| 330 | 281 | |
| 331 | - removeFieldError( fieldContainer ); | |
| 282 | + removeFieldError( $fieldCont ); | |
| 332 | 283 | if ( Object.keys( errors ).length > 0 ) { |
| 333 | 284 | for ( key in errors ) { |
| 334 | - addFieldError( fieldContainer, key, errors ); | |
| 285 | + addFieldError( $fieldCont, key, errors ); | |
| 335 | 286 | } |
| 336 | 287 | } |
| 337 | 288 | } |
| 338 | 289 | |
| @@ -359,12 +310,8 @@ | ||
| 359 | 310 | } else if ( field.pattern !== null ) { |
| 360 | 311 | checkPatternField( field, errors ); |
| 361 | 312 | } |
| 362 | 313 | |
| 363 | - if ( 'tel' === field.type && shouldCheckConfirmField( field, onSubmit ) ) { | |
| 364 | - confirmField( field, errors ); | |
| 365 | - } | |
| 366 | - | |
| 367 | 314 | /** |
| 368 | 315 | * @since 6.15 Added `onSubmit` to the data. |
| 369 | 316 | */ |
| 370 | 317 | triggerCustomEvent( document, 'frm_validate_field_value', { |
| @@ -370,18 +317,13 @@ | ||
| 370 | 317 | triggerCustomEvent( document, 'frm_validate_field_value', { |
| 371 | 318 | field: field, |
| 372 | 319 | errors: errors, |
| 373 | 320 | onSubmit: onSubmit |
| 374 | - } ); | |
| 321 | + }); | |
| 375 | 322 | } |
| 376 | 323 | |
| 377 | - /** | |
| 378 | - * @param {HTMLElement} field | |
| 379 | - * @param {Array} errors | |
| 380 | - * @return {Array} Errors | |
| 381 | - */ | |
| 382 | 324 | function checkRequiredField( field, errors ) { |
| 383 | - let tempVal, i, placeholder, | |
| 325 | + let checkGroup, tempVal, i, placeholder, | |
| 384 | 326 | val = '', |
| 385 | 327 | fieldID = '', |
| 386 | 328 | fileID = field.getAttribute( 'data-frmfile' ); |
| 387 | 329 | |
| @@ -389,19 +331,12 @@ | ||
| 389 | 331 | return errors; |
| 390 | 332 | } |
| 391 | 333 | |
| 392 | 334 | 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 | - } ); | |
| 335 | + checkGroup = jQuery( 'input[name="' + field.name + '"]' ).closest( '.frm_required_field' ).find( 'input:checked' ); | |
| 336 | + jQuery( checkGroup ).each( function() { | |
| 337 | + val = this.value; | |
| 338 | + }); | |
| 404 | 339 | } else if ( field.type === 'file' || fileID ) { |
| 405 | 340 | if ( typeof fileID === 'undefined' ) { |
| 406 | 341 | fileID = getFieldId( field, true ); |
| 407 | 342 | fileID = fileID.replace( 'file', '' ); |
| @@ -417,9 +352,8 @@ | ||
| 417 | 352 | return errors; |
| 418 | 353 | } |
| 419 | 354 | |
| 420 | 355 | val = jQuery( field ).val(); |
| 421 | - | |
| 422 | 356 | if ( val === null ) { |
| 423 | 357 | val = ''; |
| 424 | 358 | } else if ( typeof val !== 'string' ) { |
| 425 | 359 | tempVal = val; |
| @@ -424,10 +358,10 @@ | ||
| 424 | 358 | } else if ( typeof val !== 'string' ) { |
| 425 | 359 | tempVal = val; |
| 426 | 360 | val = ''; |
| 427 | 361 | for ( i = 0; i < tempVal.length; i++ ) { |
| 428 | - if ( tempVal[ i ] !== '' ) { | |
| 429 | - val = tempVal[ i ]; | |
| 362 | + if ( tempVal[i] !== '' ) { | |
| 363 | + val = tempVal[i]; | |
| 430 | 364 | } |
| 431 | 365 | } |
| 432 | 366 | } |
| 433 | 367 | |
| @@ -451,11 +385,9 @@ | ||
| 451 | 385 | // set id for time field |
| 452 | 386 | fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' ); |
| 453 | 387 | } else if ( isSignatureField( field ) ) { |
| 454 | 388 | 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 : ''; | |
| 389 | + val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val(); | |
| 458 | 390 | } |
| 459 | 391 | fieldID = fieldID.replace( '-typed', '' ); |
| 460 | 392 | } |
| 461 | 393 | |
| @@ -476,54 +408,33 @@ | ||
| 476 | 408 | |
| 477 | 409 | return errors; |
| 478 | 410 | } |
| 479 | 411 | |
| 480 | - /** | |
| 481 | - * @param {HTMLElement} field | |
| 482 | - * @return {boolean} True if the input is a typed signature input. | |
| 483 | - */ | |
| 484 | 412 | function isSignatureField( field ) { |
| 485 | 413 | const name = field.getAttribute( 'name' ); |
| 486 | 414 | return 'string' === typeof name && '[typed]' === name.substr( -7 ); |
| 487 | 415 | } |
| 488 | 416 | |
| 489 | - /** | |
| 490 | - * @param {HTMLElement} field | |
| 491 | - * @return {boolean} True if the field is a SSA appointment field. | |
| 492 | - */ | |
| 493 | 417 | function isAppointmentField( field ) { |
| 494 | 418 | return hasClass( field, 'ssa_appointment_form_field_appointment_id' ); |
| 495 | 419 | } |
| 496 | 420 | |
| 497 | - /** | |
| 498 | - * @param {HTMLElement} field | |
| 499 | - * @return {boolean} True if the field is inline datepicker field. | |
| 500 | - */ | |
| 501 | 421 | function isInlineDatepickerField( field ) { |
| 502 | 422 | return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' ); |
| 503 | 423 | } |
| 504 | 424 | |
| 505 | - /** | |
| 506 | - * @param {string|number} fileID | |
| 507 | - * @return {string} File input value. | |
| 508 | - */ | |
| 509 | 425 | function getFileVals( fileID ) { |
| 510 | - let val = ''; | |
| 511 | - const fileFields = document.querySelectorAll( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); | |
| 426 | + let val = '', | |
| 427 | + fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); | |
| 512 | 428 | |
| 513 | - fileFields.forEach( function( field ) { | |
| 429 | + fileFields.each( function() { | |
| 514 | 430 | if ( val === '' ) { |
| 515 | - val = field.value; | |
| 431 | + val = this.value; | |
| 516 | 432 | } |
| 517 | - } ); | |
| 433 | + }); | |
| 518 | 434 | return val; |
| 519 | 435 | } |
| 520 | 436 | |
| 521 | - /** | |
| 522 | - * @param {HTMLElement} field | |
| 523 | - * @param {Array} errors | |
| 524 | - * @return {void} | |
| 525 | - */ | |
| 526 | 437 | function checkUrlField( field, errors ) { |
| 527 | 438 | let fieldID, |
| 528 | 439 | url = field.value; |
| 529 | 440 | |
| @@ -541,9 +452,8 @@ | ||
| 541 | 452 | * @since 6.15 |
| 542 | 453 | * |
| 543 | 454 | * @param {HTMLElement} field Field input. |
| 544 | 455 | * @param {boolean} onSubmit Is `true` if the form is being submitted. |
| 545 | - * @return {boolean} True if we should confirm the field. | |
| 546 | 456 | */ |
| 547 | 457 | function shouldCheckConfirmField( field, onSubmit ) { |
| 548 | 458 | if ( onSubmit ) { |
| 549 | 459 | // Always check on submitting. |
| @@ -595,13 +505,8 @@ | ||
| 595 | 505 | confirmField( field, errors ); |
| 596 | 506 | } |
| 597 | 507 | } |
| 598 | 508 | |
| 599 | - /** | |
| 600 | - * @param {HTMLElement} field | |
| 601 | - * @param {Array} errors | |
| 602 | - * @return {void} | |
| 603 | - */ | |
| 604 | 509 | function confirmField( field, errors ) { |
| 605 | 510 | let value, confirmValue, firstField, |
| 606 | 511 | fieldID = getFieldId( field, true ), |
| 607 | 512 | strippedId = field.id.replace( 'conf_', '' ), |
| @@ -623,13 +528,8 @@ | ||
| 623 | 528 | validateField( confirmField ); |
| 624 | 529 | } |
| 625 | 530 | } |
| 626 | 531 | |
| 627 | - /** | |
| 628 | - * @param {HTMLElement} field | |
| 629 | - * @param {Array} errors | |
| 630 | - * @return {void} | |
| 631 | - */ | |
| 632 | 532 | function checkNumberField( field, errors ) { |
| 633 | 533 | let fieldID, |
| 634 | 534 | number = field.value; |
| 635 | 535 | |
| @@ -640,13 +540,8 @@ | ||
| 640 | 540 | } |
| 641 | 541 | } |
| 642 | 542 | } |
| 643 | 543 | |
| 644 | - /** | |
| 645 | - * @param {HTMLElement} field | |
| 646 | - * @param {Array} errors | |
| 647 | - * @return {void} | |
| 648 | - */ | |
| 649 | 544 | function checkPatternField( field, errors ) { |
| 650 | 545 | let fieldID, |
| 651 | 546 | text = field.value, |
| 652 | 547 | format = getFieldValidationMessage( field, 'pattern' ); |
| @@ -685,9 +580,9 @@ | ||
| 685 | 580 | } |
| 686 | 581 | |
| 687 | 582 | // Function to change the color of a select element |
| 688 | 583 | changeSelectColor = function( select ) { |
| 689 | - if ( select.options[ select.selectedIndex ] && hasClass( select.options[ select.selectedIndex ], 'frm-select-placeholder' ) ) { | |
| 584 | + if ( select.options[select.selectedIndex] && hasClass( select.options[select.selectedIndex], 'frm-select-placeholder' ) ) { | |
| 690 | 585 | select.style.setProperty( 'color', textColorDisabled, 'important' ); |
| 691 | 586 | } else { |
| 692 | 587 | select.style.color = ''; |
| 693 | 588 | } |
| @@ -700,68 +595,50 @@ | ||
| 700 | 595 | |
| 701 | 596 | // Add an event listener for future changes |
| 702 | 597 | select.addEventListener( 'change', function() { |
| 703 | 598 | changeSelectColor( select ); |
| 704 | - } ); | |
| 705 | - } ); | |
| 599 | + }); | |
| 600 | + }); | |
| 706 | 601 | } |
| 707 | 602 | |
| 708 | - /** | |
| 709 | - * @param {HTMLElement|jQuery} object | |
| 710 | - * | |
| 711 | - * @return {HTMLElement|false} Captcha element if there is an invisible recaptcha. | |
| 712 | - */ | |
| 713 | 603 | function hasInvisibleRecaptcha( object ) { |
| 604 | + let recaptcha, recaptchaID, alreadyChecked; | |
| 605 | + | |
| 714 | 606 | if ( isGoingToPrevPage( object ) ) { |
| 715 | 607 | return false; |
| 716 | 608 | } |
| 717 | 609 | |
| 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 ); | |
| 610 | + recaptcha = jQuery( object ).find( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' ); | |
| 611 | + if ( recaptcha.length ) { | |
| 612 | + recaptchaID = recaptcha.data( 'rid' ); | |
| 613 | + alreadyChecked = grecaptcha.getResponse( recaptchaID ); | |
| 727 | 614 | if ( alreadyChecked.length === 0 ) { |
| 728 | 615 | return recaptcha; |
| 729 | 616 | } |
| 730 | 617 | } |
| 731 | - | |
| 732 | 618 | return false; |
| 733 | 619 | } |
| 734 | 620 | |
| 735 | - /** | |
| 736 | - * @param {HTMLElement} invisibleRecaptcha | |
| 737 | - * | |
| 738 | - * @return {void} | |
| 739 | - */ | |
| 740 | 621 | function executeInvisibleRecaptcha( invisibleRecaptcha ) { |
| 741 | - const recaptchaID = invisibleRecaptcha.dataset.rid; | |
| 622 | + const recaptchaID = invisibleRecaptcha.data( 'rid' ); | |
| 742 | 623 | grecaptcha.reset( recaptchaID ); |
| 743 | 624 | grecaptcha.execute( recaptchaID ); |
| 744 | 625 | } |
| 745 | 626 | |
| 746 | 627 | function validateRecaptcha( form, errors ) { |
| 747 | - const formEl = form instanceof jQuery ? form.get( 0 ) : form; | |
| 748 | - if ( ! formEl ) { | |
| 749 | - return errors; | |
| 750 | - } | |
| 628 | + let response; | |
| 751 | 629 | |
| 752 | - const recaptcha = formEl.querySelector( '.frm-g-recaptcha' ); | |
| 753 | - if ( ! recaptcha ) { | |
| 630 | + const $recaptcha = jQuery( form ).find( '.frm-g-recaptcha' ); | |
| 631 | + if ( ! $recaptcha.length ) { | |
| 754 | 632 | return errors; |
| 755 | 633 | } |
| 756 | 634 | |
| 757 | - const recaptchaID = recaptcha.dataset.rid; | |
| 758 | - let response; | |
| 635 | + const recaptchaID = $recaptcha.data( 'rid' ); | |
| 759 | 636 | |
| 760 | 637 | try { |
| 761 | 638 | response = grecaptcha.getResponse( recaptchaID ); |
| 762 | 639 | } catch ( e ) { |
| 763 | - if ( formEl.querySelector( 'input[name="recaptcha_checked"]' ) ) { | |
| 640 | + if ( jQuery( form ).find( 'input[name="recaptcha_checked"]' ).length ) { | |
| 764 | 641 | return errors; |
| 765 | 642 | } |
| 766 | 643 | response = ''; |
| 767 | 644 | } |
| @@ -766,13 +643,11 @@ | ||
| 766 | 643 | response = ''; |
| 767 | 644 | } |
| 768 | 645 | |
| 769 | 646 | if ( response.length === 0 ) { |
| 770 | - const fieldContainer = recaptcha.closest( '.frm_form_field' ); | |
| 771 | - if ( fieldContainer && fieldContainer.id ) { | |
| 772 | - const fieldID = fieldContainer.id.replace( 'frm_field_', '' ).replace( '_container', '' ); | |
| 773 | - errors[ fieldID ] = ''; | |
| 774 | - } | |
| 647 | + const fieldContainer = $recaptcha.closest( '.frm_form_field' ); | |
| 648 | + const fieldID = fieldContainer.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_container', '' ); | |
| 649 | + errors[ fieldID ] = ''; | |
| 775 | 650 | } |
| 776 | 651 | |
| 777 | 652 | return errors; |
| 778 | 653 | } |
| @@ -805,15 +680,15 @@ | ||
| 805 | 680 | if ( null === errorHtml ) { |
| 806 | 681 | return msg; |
| 807 | 682 | } |
| 808 | 683 | |
| 809 | - errorHtml = errorHtml.replace( /\+/g, '%20' ); | |
| 810 | - msg = decodeURIComponent( errorHtml ).replace( '[error]', msg ); | |
| 811 | - const fieldId = getFieldId( field, false ); | |
| 812 | - const split = fieldId.split( '-' ); | |
| 684 | + errorHtml = errorHtml.replace( /\+/g, '%20' ); | |
| 685 | + msg = decodeURIComponent( errorHtml ).replace( '[error]', msg ); | |
| 686 | + const fieldId = getFieldId( field, false ); | |
| 687 | + const split = fieldId.split( '-' ); | |
| 813 | 688 | const fieldIdParts = field.id.split( '_' ); |
| 814 | 689 | fieldIdParts.shift(); // Drop the "field" value from the front. |
| 815 | - split[ 0 ] = fieldIdParts.join( '_' ); | |
| 690 | + split[0] = fieldIdParts.join( '_' ); | |
| 816 | 691 | const errorKey = split.join( '-' ); |
| 817 | 692 | return msg.replace( '[key]', errorKey ); |
| 818 | 693 | } |
| 819 | 694 | |
| @@ -840,40 +715,28 @@ | ||
| 840 | 715 | return validate; |
| 841 | 716 | } |
| 842 | 717 | |
| 843 | 718 | /** |
| 844 | - * @param {HTMLElement} object | |
| 845 | - * @param {string} action | |
| 719 | + * @param {HTMLElement} object | |
| 720 | + * @param {string|undefined} action | |
| 846 | 721 | * @return {void} |
| 847 | 722 | */ |
| 848 | 723 | function getFormErrors( object, action ) { |
| 849 | - let data, success, error, shouldTriggerEvent; | |
| 724 | + let fieldset, data, success, error, shouldTriggerEvent; | |
| 850 | 725 | |
| 851 | - const fieldsets = object.querySelectorAll( '.frm_form_field' ); | |
| 852 | - fieldsets.forEach( field => field.classList.add( 'frm_doing_ajax' ) ); | |
| 726 | + if ( typeof action === 'undefined' ) { | |
| 727 | + jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 728 | + } | |
| 853 | 729 | |
| 854 | - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase | |
| 730 | + fieldset = jQuery( object ).find( '.frm_form_field' ); | |
| 731 | + fieldset.addClass( 'frm_doing_ajax' ); | |
| 732 | + | |
| 733 | + data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase | |
| 855 | 734 | shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' ); |
| 856 | 735 | |
| 857 | - const doRedirect = response => { | |
| 858 | - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ] ); | |
| 859 | - | |
| 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 | 736 | success = function( response ) { |
| 874 | 737 | let defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay, |
| 875 | - $fieldCont, key, inCollapsedSection, frmTrigger; | |
| 738 | + $fieldCont, key, inCollapsedSection, frmTrigger, newTab; | |
| 876 | 739 | |
| 877 | 740 | defaultResponse = { |
| 878 | 741 | content: '', |
| 879 | 742 | errors: {}, |
| @@ -881,16 +744,15 @@ | ||
| 881 | 744 | }; |
| 882 | 745 | |
| 883 | 746 | if ( response === null ) { |
| 884 | 747 | response = defaultResponse; |
| 748 | + } | |
| 749 | + | |
| 750 | + response = response.replace( /^\s+|\s+$/g, '' ); | |
| 751 | + if ( response.indexOf( '{' ) === 0 ) { | |
| 752 | + response = JSON.parse( response ); | |
| 885 | 753 | } 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 | - } | |
| 754 | + response = defaultResponse; | |
| 893 | 755 | } |
| 894 | 756 | |
| 895 | 757 | if ( typeof response.redirect !== 'undefined' ) { |
| 896 | 758 | if ( shouldTriggerEvent ) { |
| @@ -897,22 +759,28 @@ | ||
| 897 | 759 | triggerCustomEvent( object, 'frmSubmitEvent' ); |
| 898 | 760 | return; |
| 899 | 761 | } |
| 900 | 762 | |
| 901 | - if ( response.delay ) { | |
| 902 | - setTimeout( function() { | |
| 903 | - doRedirect( response ); | |
| 904 | - }, 1000 * response.delay ); | |
| 905 | - } else { | |
| 906 | - doRedirect( response ); | |
| 763 | + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]); | |
| 764 | + | |
| 765 | + if ( ! response.openInNewTab ) { | |
| 766 | + // We return here because we're redirecting there is no need to update content. | |
| 767 | + window.location = response.redirect; | |
| 768 | + return; | |
| 907 | 769 | } |
| 770 | + | |
| 771 | + // We don't return here because we're opening in a new tab, the old tab will still update. | |
| 772 | + newTab = window.open( response.redirect, '_blank' ); | |
| 773 | + if ( ! newTab && response.fallbackMsg && response.content ) { | |
| 774 | + response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' ); | |
| 775 | + } | |
| 908 | 776 | } |
| 909 | 777 | |
| 910 | - if ( 'string' === typeof response.content && response.content !== '' ) { | |
| 778 | + if ( response.content !== '' ) { | |
| 911 | 779 | // the form or success message was returned |
| 912 | 780 | |
| 913 | 781 | if ( shouldTriggerEvent ) { |
| 914 | - triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content } ); | |
| 782 | + triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content }); | |
| 915 | 783 | return; |
| 916 | 784 | } |
| 917 | 785 | |
| 918 | 786 | removeSubmitLoading( jQuery( object ) ); |
| @@ -919,10 +787,9 @@ | ||
| 919 | 787 | if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase |
| 920 | 788 | frmFrontForm.scrollMsg( jQuery( object ), false ); |
| 921 | 789 | } |
| 922 | 790 | |
| 923 | - const formIdInput = object.querySelector( 'input[name="form_id"]' ); | |
| 924 | - formID = formIdInput ? formIdInput.value : ''; | |
| 791 | + formID = jQuery( object ).find( 'input[name="form_id"]' ).val(); | |
| 925 | 792 | response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' ); |
| 926 | 793 | replaceContent = jQuery( object ).closest( '.frm_forms' ); |
| 927 | 794 | removeAddedScripts( replaceContent, formID ); |
| 928 | 795 | delay = maybeSlideOut( replaceContent, response.content ); |
| @@ -928,8 +795,10 @@ | ||
| 928 | 795 | delay = maybeSlideOut( replaceContent, response.content ); |
| 929 | 796 | |
| 930 | 797 | setTimeout( |
| 931 | 798 | function() { |
| 799 | + let container, input, previousInput; | |
| 800 | + | |
| 932 | 801 | afterFormSubmittedBeforeReplace( object, response ); |
| 933 | 802 | |
| 934 | 803 | replaceContent.replaceWith( response.content ); |
| 935 | 804 | |
| @@ -935,17 +804,25 @@ | ||
| 935 | 804 | |
| 936 | 805 | addUrlParam( response ); |
| 937 | 806 | |
| 938 | 807 | 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 : ''; | |
| 808 | + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val(); | |
| 809 | + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val(); | |
| 945 | 810 | frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object ); |
| 946 | 811 | } |
| 947 | 812 | |
| 813 | + if ( typeof response.recaptcha !== 'undefined' ) { | |
| 814 | + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' ); | |
| 815 | + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">'; | |
| 816 | + previousInput = container.find( 'input[name="recaptcha_checked"]' ); | |
| 817 | + | |
| 818 | + if ( previousInput.length ) { | |
| 819 | + previousInput.replaceWith( input ); | |
| 820 | + } else { | |
| 821 | + container.append( input ); | |
| 822 | + } | |
| 823 | + } | |
| 824 | + | |
| 948 | 825 | afterFormSubmitted( object, response ); |
| 949 | 826 | }, |
| 950 | 827 | delay |
| 951 | 828 | ); |
| @@ -959,10 +836,9 @@ | ||
| 959 | 836 | |
| 960 | 837 | $fieldCont = null; |
| 961 | 838 | |
| 962 | 839 | for ( key in response.errors ) { |
| 963 | - const fieldContEl = object.querySelector( '#frm_field_' + key + '_container' ); | |
| 964 | - $fieldCont = fieldContEl ? jQuery( fieldContEl ) : jQuery(); | |
| 840 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 965 | 841 | |
| 966 | 842 | if ( $fieldCont.length ) { |
| 967 | 843 | if ( ! $fieldCont.is( ':visible' ) ) { |
| 968 | 844 | inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); |
| @@ -982,10 +858,11 @@ | ||
| 982 | 858 | } |
| 983 | 859 | } |
| 984 | 860 | } |
| 985 | 861 | |
| 986 | - object.querySelectorAll( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).forEach( function( captchaEl ) { | |
| 987 | - const recaptchaID = captchaEl.dataset.rid; | |
| 862 | + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() { | |
| 863 | + const $recaptcha = jQuery( this ), | |
| 864 | + recaptchaID = $recaptcha.data( 'rid' ); | |
| 988 | 865 | |
| 989 | 866 | if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { |
| 990 | 867 | if ( recaptchaID ) { |
| 991 | 868 | grecaptcha.reset( recaptchaID ); |
| @@ -992,23 +869,16 @@ | ||
| 992 | 869 | } else { |
| 993 | 870 | grecaptcha.reset(); |
| 994 | 871 | } |
| 995 | 872 | } |
| 996 | - | |
| 997 | 873 | if ( typeof hcaptcha !== 'undefined' && hcaptcha ) { |
| 998 | 874 | hcaptcha.reset(); |
| 999 | 875 | } |
| 1000 | - } ); | |
| 876 | + }); | |
| 1001 | 877 | |
| 1002 | - if ( window.turnstile ) { | |
| 1003 | - object.querySelectorAll( '.frm-cf-turnstile' ).forEach( | |
| 1004 | - turnstileField => turnstileField.dataset.rid && turnstile.reset( turnstileField.dataset.rid ) | |
| 1005 | - ); | |
| 1006 | - } | |
| 878 | + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 1007 | 879 | |
| 1008 | - jQuery( document ).trigger( 'frmFormErrors', [ object, response ] ); | |
| 1009 | - | |
| 1010 | - fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) ); | |
| 880 | + fieldset.removeClass( 'frm_doing_ajax' ); | |
| 1011 | 881 | scrollToFirstField( object ); |
| 1012 | 882 | |
| 1013 | 883 | if ( contSubmit ) { |
| 1014 | 884 | object.submit(); |
| @@ -1025,11 +895,9 @@ | ||
| 1025 | 895 | } |
| 1026 | 896 | }; |
| 1027 | 897 | |
| 1028 | 898 | error = function() { |
| 1029 | - object.querySelectorAll( 'input[type="submit"], input[type="button"]' ).forEach( | |
| 1030 | - button => button.disabled = false | |
| 1031 | - ); | |
| 899 | + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false ); | |
| 1032 | 900 | object.submit(); |
| 1033 | 901 | }; |
| 1034 | 902 | |
| 1035 | 903 | postToAjaxUrl( object, data, success, error ); |
| @@ -1041,9 +909,9 @@ | ||
| 1041 | 909 | ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase |
| 1042 | 910 | action = form.getAttribute( 'action' ); |
| 1043 | 911 | |
| 1044 | 912 | if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) { |
| 1045 | - ajaxUrl = action.split( '?action=frm_forms_preview' )[ 0 ]; | |
| 913 | + ajaxUrl = action.split( '?action=frm_forms_preview' )[0]; | |
| 1046 | 914 | } |
| 1047 | 915 | |
| 1048 | 916 | ajaxParams = { |
| 1049 | 917 | type: 'POST', |
| @@ -1059,15 +927,13 @@ | ||
| 1059 | 927 | jQuery.ajax( ajaxParams ); |
| 1060 | 928 | } |
| 1061 | 929 | |
| 1062 | 930 | 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 ] ); | |
| 931 | + const formCompleted = jQuery( response.content ).find( '.frm_message' ); | |
| 932 | + if ( formCompleted.length ) { | |
| 933 | + jQuery( document ).trigger( 'frmFormComplete', [ object, response ]); | |
| 1068 | 934 | } else { |
| 1069 | - jQuery( document ).trigger( 'frmPageChanged', [ object, response ] ); | |
| 935 | + jQuery( document ).trigger( 'frmPageChanged', [ object, response ]); | |
| 1070 | 936 | } |
| 1071 | 937 | } |
| 1072 | 938 | |
| 1073 | 939 | /** |
| @@ -1079,21 +945,19 @@ | ||
| 1079 | 945 | * @param {Object} response The response from submitting the form with AJAX. |
| 1080 | 946 | * @return {void} |
| 1081 | 947 | */ |
| 1082 | 948 | 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 } ); | |
| 949 | + const formCompleted = jQuery( response.content ).find( '.frm_message' ); | |
| 950 | + if ( formCompleted.length ) { | |
| 951 | + triggerCustomEvent( document, 'frmFormCompleteBeforeReplace', { object, response }); | |
| 1088 | 952 | } |
| 1089 | 953 | } |
| 1090 | 954 | |
| 1091 | 955 | function removeAddedScripts( formContainer, formID ) { |
| 1092 | - const endReplace = document.querySelectorAll( '.frm_end_ajax_' + formID ); | |
| 956 | + const endReplace = jQuery( '.frm_end_ajax_' + formID ); | |
| 1093 | 957 | if ( endReplace.length ) { |
| 1094 | 958 | formContainer.nextUntil( '.frm_end_ajax_' + formID ).remove(); |
| 1095 | - endReplace.forEach( el => el.remove() ); | |
| 959 | + endReplace.remove(); | |
| 1096 | 960 | } |
| 1097 | 961 | } |
| 1098 | 962 | |
| 1099 | 963 | function maybeSlideOut( oldContent, newContent ) { |
| @@ -1114,9 +978,9 @@ | ||
| 1114 | 978 | function addUrlParam( response ) { |
| 1115 | 979 | let url; |
| 1116 | 980 | if ( history.pushState && typeof response.page !== 'undefined' ) { |
| 1117 | 981 | url = addQueryVar( 'frm_page', response.page ); |
| 1118 | - window.history.pushState( { html: response.html }, '', '?' + url ); | |
| 982 | + window.history.pushState({ 'html': response.html }, '', '?' + url ); | |
| 1119 | 983 | } |
| 1120 | 984 | } |
| 1121 | 985 | |
| 1122 | 986 | function addQueryVar( key, value ) { |
| @@ -1128,13 +992,13 @@ | ||
| 1128 | 992 | kvp = document.location.search.substr( 1 ).split( '&' ); |
| 1129 | 993 | |
| 1130 | 994 | i = kvp.length; |
| 1131 | 995 | while ( i-- ) { |
| 1132 | - x = kvp[ i ].split( '=' ); | |
| 996 | + x = kvp[i].split( '=' ); | |
| 1133 | 997 | |
| 1134 | - if ( x[ 0 ] == key ) { | |
| 1135 | - x[ 1 ] = value; | |
| 1136 | - kvp[ i ] = x.join( '=' ); | |
| 998 | + if ( x[0] == key ) { | |
| 999 | + x[1] = value; | |
| 1000 | + kvp[i] = x.join( '=' ); | |
| 1137 | 1001 | break; |
| 1138 | 1002 | } |
| 1139 | 1003 | } |
| 1140 | 1004 | |
| @@ -1145,59 +1009,44 @@ | ||
| 1145 | 1009 | return kvp.join( '&' ); |
| 1146 | 1010 | } |
| 1147 | 1011 | |
| 1148 | 1012 | 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 | - } | |
| 1013 | + let input, id, describedBy, roleString; | |
| 1014 | + if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) { | |
| 1015 | + $fieldCont.addClass( 'frm_blank_field' ); | |
| 1016 | + input = $fieldCont.find( 'input, select, textarea' ); | |
| 1017 | + id = getErrorElementId( key, input.get( 0 ) ); | |
| 1154 | 1018 | |
| 1155 | - container.classList.add( 'frm_blank_field' ); | |
| 1156 | - const input = container.querySelector( 'input, select, textarea' ); | |
| 1157 | - id = getErrorElementId( key, input ); | |
| 1019 | + describedBy = input.attr( 'aria-describedby' ); | |
| 1158 | 1020 | |
| 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 ]; | |
| 1021 | + if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase | |
| 1022 | + frmThemeOverride_frmPlaceError( key, jsErrors ); | |
| 1167 | 1023 | } 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 ); | |
| 1024 | + if ( -1 !== jsErrors[key].indexOf( '<div' ) ) { | |
| 1025 | + $fieldCont.append( | |
| 1026 | + jsErrors[key] | |
| 1027 | + ); | |
| 1028 | + } else { | |
| 1029 | + roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase | |
| 1030 | + $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' ); | |
| 1031 | + } | |
| 1172 | 1032 | |
| 1173 | - if ( input ) { | |
| 1174 | - if ( ! describedBy ) { | |
| 1033 | + if ( typeof describedBy === 'undefined' ) { | |
| 1175 | 1034 | describedBy = id; |
| 1176 | 1035 | } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) { |
| 1177 | - const errorFirst = input.dataset.errorFirst; | |
| 1178 | - if ( errorFirst === '0' ) { | |
| 1036 | + if ( input.data( 'error-first' ) === 0 ) { | |
| 1179 | 1037 | describedBy = describedBy + ' ' + id; |
| 1180 | 1038 | } else { |
| 1181 | 1039 | describedBy = id + ' ' + describedBy; |
| 1182 | 1040 | } |
| 1183 | 1041 | } |
| 1184 | - input.setAttribute( 'aria-describedby', describedBy ); | |
| 1042 | + | |
| 1043 | + input.attr( 'aria-describedby', describedBy ); | |
| 1185 | 1044 | } |
| 1186 | - } | |
| 1045 | + input.attr( 'aria-invalid', true ); | |
| 1187 | 1046 | |
| 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 | - } | |
| 1047 | + jQuery( document ).trigger( 'frmAddFieldError', [ $fieldCont, key, jsErrors ]); | |
| 1197 | 1048 | } |
| 1198 | - | |
| 1199 | - jQuery( document ).trigger( 'frmAddFieldError', [ jQuery( container ), key, jsErrors ] ); | |
| 1200 | 1049 | } |
| 1201 | 1050 | |
| 1202 | 1051 | /** |
| 1203 | 1052 | * Get the ID to use for an error element added when submitting with AJAX. |
| @@ -1206,9 +1055,9 @@ | ||
| 1206 | 1055 | * @param {HTMLElement} input |
| 1207 | 1056 | * @return {string} The ID to use for the error element. |
| 1208 | 1057 | */ |
| 1209 | 1058 | function getErrorElementId( key, input ) { |
| 1210 | - if ( isNaN( key ) || ! input || ! input.id ) { | |
| 1059 | + if ( isNaN( key ) || ! input.id ) { | |
| 1211 | 1060 | // If key isn't a number, assume it's already in the right format. |
| 1212 | 1061 | return 'frm_error_field_' + key; |
| 1213 | 1062 | } |
| 1214 | 1063 | return 'frm_error_' + input.id; |
| @@ -1217,56 +1066,36 @@ | ||
| 1217 | 1066 | /** |
| 1218 | 1067 | * Removes errors before validating with JS. |
| 1219 | 1068 | * This prevents issues with stale errors that has since been fixed. |
| 1220 | 1069 | * |
| 1221 | - * @param {HTMLElement|jQuery} fieldCont Field container element. | |
| 1070 | + * @param {Object} $fieldCont jQuery object. | |
| 1222 | 1071 | * @return {void} |
| 1223 | 1072 | */ |
| 1224 | - function removeFieldError( fieldCont ) { | |
| 1225 | - const container = fieldCont instanceof jQuery ? fieldCont.get( 0 ) : fieldCont; | |
| 1226 | - if ( ! container ) { | |
| 1227 | - return; | |
| 1228 | - } | |
| 1073 | + function removeFieldError( $fieldCont ) { | |
| 1074 | + const errorMessage = $fieldCont.find( '.frm_error' ); | |
| 1075 | + const errorId = errorMessage.attr( 'id' ); | |
| 1076 | + const input = $fieldCont.find( 'input, select, textarea' ); | |
| 1077 | + let describedBy = input.attr( 'aria-describedby' ); | |
| 1229 | 1078 | |
| 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 | - } | |
| 1079 | + const fieldContainer = $fieldCont.get( 0 ); | |
| 1080 | + if ( fieldContainer && fieldContainer.classList ) { | |
| 1081 | + fieldContainer.classList.remove( 'frm_blank_field', 'has-error' ); | |
| 1246 | 1082 | } |
| 1247 | 1083 | |
| 1248 | - if ( errorMessage ) { | |
| 1249 | - errorMessage.remove(); | |
| 1250 | - } | |
| 1084 | + errorMessage.remove(); | |
| 1085 | + input.attr( 'aria-invalid', false ); | |
| 1086 | + input.removeAttr( 'aria-describedby' ); | |
| 1251 | 1087 | |
| 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 | - } | |
| 1088 | + if ( typeof describedBy !== 'undefined' ) { | |
| 1089 | + describedBy = describedBy.replace( errorId, '' ); | |
| 1090 | + input.attr( 'aria-describedby', describedBy ); | |
| 1260 | 1091 | } |
| 1261 | 1092 | } |
| 1262 | 1093 | |
| 1263 | 1094 | 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() ); | |
| 1095 | + jQuery( '.form-field' ).removeClass( 'frm_blank_field has-error' ); | |
| 1096 | + jQuery( '.form-field .frm_error' ).replaceWith( '' ); | |
| 1097 | + jQuery( '.frm_error_style' ).remove(); | |
| 1269 | 1098 | } |
| 1270 | 1099 | |
| 1271 | 1100 | /** |
| 1272 | 1101 | * @param {HTMLElement|Object} object Form object. |
| @@ -1305,37 +1134,38 @@ | ||
| 1305 | 1134 | function isGoingToPrevPage( $object ) { |
| 1306 | 1135 | return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) ); |
| 1307 | 1136 | } |
| 1308 | 1137 | |
| 1309 | - function removeSubmitLoading( _, enable, processesRunning ) { | |
| 1138 | + function removeSubmitLoading( $object, enable, processesRunning ) { | |
| 1139 | + let loadingForm; | |
| 1140 | + | |
| 1310 | 1141 | if ( processesRunning > 0 ) { |
| 1311 | 1142 | return; |
| 1312 | 1143 | } |
| 1313 | 1144 | |
| 1314 | - document.querySelectorAll( '.frm_loading_form' ).forEach( function( form ) { | |
| 1315 | - form.classList.remove( 'frm_loading_form', 'frm_loading_prev' ); | |
| 1316 | - jQuery( form ).trigger( 'frmEndFormLoading' ); | |
| 1145 | + loadingForm = jQuery( '.frm_loading_form' ); | |
| 1146 | + loadingForm.removeClass( 'frm_loading_form' ); | |
| 1147 | + loadingForm.removeClass( 'frm_loading_prev' ); | |
| 1317 | 1148 | |
| 1318 | - if ( enable === 'enable' ) { | |
| 1319 | - enableSubmitButton( form ); | |
| 1320 | - enableSaveDraft( form ); | |
| 1321 | - } | |
| 1322 | - } ); | |
| 1149 | + loadingForm.trigger( 'frmEndFormLoading' ); | |
| 1150 | + | |
| 1151 | + if ( enable === 'enable' ) { | |
| 1152 | + enableSubmitButton( loadingForm ); | |
| 1153 | + enableSaveDraft( loadingForm ); | |
| 1154 | + } | |
| 1323 | 1155 | } |
| 1324 | 1156 | |
| 1325 | 1157 | function showFileLoading( object ) { |
| 1326 | - const loading = document.getElementById( 'frm_loading' ); | |
| 1327 | - if ( loading === null ) { | |
| 1328 | - return; | |
| 1158 | + let fileval, | |
| 1159 | + loading = document.getElementById( 'frm_loading' ); | |
| 1160 | + if ( loading !== null ) { | |
| 1161 | + fileval = jQuery( object ).find( 'input[type=file]' ).val(); | |
| 1162 | + if ( typeof fileval !== 'undefined' && fileval !== '' ) { | |
| 1163 | + setTimeout( function() { | |
| 1164 | + jQuery( loading ).fadeIn( 'slow' ); | |
| 1165 | + }, 2000 ); | |
| 1166 | + } | |
| 1329 | 1167 | } |
| 1330 | - | |
| 1331 | - const fileInput = object.querySelector( 'input[type=file]' ); | |
| 1332 | - const fileval = fileInput ? fileInput.value : ''; | |
| 1333 | - if ( fileval !== '' ) { | |
| 1334 | - setTimeout( function() { | |
| 1335 | - jQuery( loading ).fadeIn( 'slow' ); | |
| 1336 | - }, 2000 ); | |
| 1337 | - } | |
| 1338 | 1168 | } |
| 1339 | 1169 | |
| 1340 | 1170 | /********************************************** |
| 1341 | 1171 | * General Helpers |
| @@ -1342,9 +1172,9 @@ | ||
| 1342 | 1172 | *********************************************/ |
| 1343 | 1173 | |
| 1344 | 1174 | function confirmClick() { |
| 1345 | 1175 | /*jshint validthis:true */ |
| 1346 | - const message = this.dataset.frmconfirm; | |
| 1176 | + const message = jQuery( this ).data( 'frmconfirm' ); | |
| 1347 | 1177 | return confirm( message ); |
| 1348 | 1178 | } |
| 1349 | 1179 | |
| 1350 | 1180 | /** |
| @@ -1352,15 +1182,43 @@ | ||
| 1352 | 1182 | * If this is a match, the User is autofilling the input on a Webkit browser. |
| 1353 | 1183 | * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete. |
| 1354 | 1184 | */ |
| 1355 | 1185 | function onHoneypotFieldChange() { |
| 1356 | - /*jshint validthis:true */ | |
| 1357 | - const css = window.getComputedStyle( this ).boxShadow; | |
| 1358 | - if ( css && css.match( /inset/ ) ) { | |
| 1186 | + const css = jQuery( this ).css( 'box-shadow' ); | |
| 1187 | + if ( css.match( /inset/ ) ) { | |
| 1359 | 1188 | this.parentNode.removeChild( this ); |
| 1360 | 1189 | } |
| 1361 | 1190 | } |
| 1362 | 1191 | |
| 1192 | + function maybeMakeHoneypotFieldsUntabbable() { | |
| 1193 | + document.addEventListener( 'keydown', handleKeyUp ); | |
| 1194 | + | |
| 1195 | + function handleKeyUp( event ) { | |
| 1196 | + let code; | |
| 1197 | + | |
| 1198 | + if ( 'undefined' !== typeof event.key ) { | |
| 1199 | + code = event.key; | |
| 1200 | + } else if ( 'undefined' !== typeof event.keyCode && 9 === event.keyCode ) { | |
| 1201 | + code = 'Tab'; | |
| 1202 | + } | |
| 1203 | + | |
| 1204 | + if ( 'Tab' === code ) { | |
| 1205 | + makeHoneypotFieldsUntabbable(); | |
| 1206 | + document.removeEventListener( 'keydown', handleKeyUp ); | |
| 1207 | + } | |
| 1208 | + } | |
| 1209 | + | |
| 1210 | + function makeHoneypotFieldsUntabbable() { | |
| 1211 | + document.querySelectorAll( '.frm_verify' ).forEach( | |
| 1212 | + function( input ) { | |
| 1213 | + if ( input.id && 0 === input.id.indexOf( 'frm_email_' ) ) { | |
| 1214 | + input.setAttribute( 'tabindex', -1 ); | |
| 1215 | + } | |
| 1216 | + } | |
| 1217 | + ); | |
| 1218 | + } | |
| 1219 | + } | |
| 1220 | + | |
| 1363 | 1221 | /** |
| 1364 | 1222 | * Focus on the first sub field when clicking to the primary label of combo field. |
| 1365 | 1223 | * |
| 1366 | 1224 | * @since 4.10.02 |
| @@ -1380,35 +1238,12 @@ | ||
| 1380 | 1238 | } |
| 1381 | 1239 | |
| 1382 | 1240 | label.addEventListener( 'click', function() { |
| 1383 | 1241 | inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus(); |
| 1384 | - } ); | |
| 1385 | - } ); | |
| 1242 | + }); | |
| 1243 | + }); | |
| 1386 | 1244 | } |
| 1387 | 1245 | |
| 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 | 1246 | function checkForErrorsAndMaybeSetFocus() { |
| 1412 | 1247 | let errors, element, timeoutCallback; |
| 1413 | 1248 | |
| 1414 | 1249 | if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase |
| @@ -1419,20 +1254,16 @@ | ||
| 1419 | 1254 | if ( ! errors.length ) { |
| 1420 | 1255 | return; |
| 1421 | 1256 | } |
| 1422 | 1257 | |
| 1423 | - element = errors[ 0 ]; | |
| 1258 | + element = errors[0]; | |
| 1424 | 1259 | do { |
| 1425 | 1260 | element = element.previousSibling; |
| 1426 | 1261 | if ( -1 !== [ 'input', 'select', 'textarea' ].indexOf( element.nodeName.toLowerCase() ) ) { |
| 1427 | - focusInput( element ); | |
| 1262 | + element.focus(); | |
| 1428 | 1263 | break; |
| 1429 | 1264 | } |
| 1430 | 1265 | |
| 1431 | - if ( maybeFocusOnComboSubField( element ) ) { | |
| 1432 | - break; | |
| 1433 | - } | |
| 1434 | - | |
| 1435 | 1266 | if ( 'undefined' !== typeof element.classList ) { |
| 1436 | 1267 | if ( element.classList.contains( 'html-active' ) ) { |
| 1437 | 1268 | timeoutCallback = function() { |
| 1438 | 1269 | const textarea = element.querySelector( 'textarea' ); |
| @@ -1443,14 +1274,8 @@ | ||
| 1443 | 1274 | } else if ( element.classList.contains( 'tmce-active' ) ) { |
| 1444 | 1275 | timeoutCallback = function() { |
| 1445 | 1276 | tinyMCE.activeEditor.focus(); |
| 1446 | 1277 | }; |
| 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 | 1278 | } |
| 1454 | 1279 | |
| 1455 | 1280 | if ( 'function' === typeof timeoutCallback ) { |
| 1456 | 1281 | setTimeout( timeoutCallback, 0 ); |
| @@ -1460,24 +1285,8 @@ | ||
| 1460 | 1285 | } while ( element.previousSibling ); |
| 1461 | 1286 | } |
| 1462 | 1287 | |
| 1463 | 1288 | /** |
| 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 | - } | |
| 1478 | - | |
| 1479 | - /** | |
| 1480 | 1289 | * Does the same as jQuery( document ).on( 'event', 'selector', handler ). |
| 1481 | 1290 | * |
| 1482 | 1291 | * @since 5.4 |
| 1483 | 1292 | * |
| @@ -1506,9 +1315,9 @@ | ||
| 1506 | 1315 | |
| 1507 | 1316 | function initFloatingLabels() { |
| 1508 | 1317 | let checkFloatLabel, checkDropdownLabel, runOnLoad, selector, floatClass; |
| 1509 | 1318 | |
| 1510 | - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea'; | |
| 1319 | + selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea'; | |
| 1511 | 1320 | floatClass = 'frm_label_float_top'; |
| 1512 | 1321 | |
| 1513 | 1322 | checkFloatLabel = function( input ) { |
| 1514 | 1323 | let container, shouldFloatTop, firstOpt; |
| @@ -1544,9 +1353,9 @@ | ||
| 1544 | 1353 | if ( firstOpt.textContent ) { |
| 1545 | 1354 | firstOpt.setAttribute( 'data-label', firstOpt.textContent ); |
| 1546 | 1355 | firstOpt.textContent = ''; |
| 1547 | 1356 | } |
| 1548 | - } ); | |
| 1357 | + }); | |
| 1549 | 1358 | }; |
| 1550 | 1359 | |
| 1551 | 1360 | [ 'focus', 'blur', 'change' ].forEach( function( eventName ) { |
| 1552 | 1361 | documentOn( |
| @@ -1556,13 +1365,13 @@ | ||
| 1556 | 1365 | checkFloatLabel( event.target ); |
| 1557 | 1366 | }, |
| 1558 | 1367 | true |
| 1559 | 1368 | ); |
| 1560 | - } ); | |
| 1369 | + }); | |
| 1561 | 1370 | |
| 1562 | 1371 | jQuery( document ).on( 'change', selector, function( event ) { |
| 1563 | 1372 | checkFloatLabel( event.target ); |
| 1564 | - } ); | |
| 1373 | + }); | |
| 1565 | 1374 | |
| 1566 | 1375 | runOnLoad = function( firstLoad ) { |
| 1567 | 1376 | if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) { |
| 1568 | 1377 | checkFloatLabel( document.activeElement ); |
| @@ -1583,13 +1392,13 @@ | ||
| 1583 | 1392 | runOnLoad( true ); |
| 1584 | 1393 | |
| 1585 | 1394 | jQuery( document ).on( 'frmPageChanged', function( event ) { |
| 1586 | 1395 | runOnLoad(); |
| 1587 | - } ); | |
| 1396 | + }); | |
| 1588 | 1397 | |
| 1589 | 1398 | document.addEventListener( 'frm_after_start_over', function( event ) { |
| 1590 | 1399 | runOnLoad(); |
| 1591 | - } ); | |
| 1400 | + }); | |
| 1592 | 1401 | } |
| 1593 | 1402 | |
| 1594 | 1403 | function shouldUpdateValidityMessage( target ) { |
| 1595 | 1404 | if ( 'INPUT' !== target.nodeName ) { |
| @@ -1626,9 +1435,9 @@ | ||
| 1626 | 1435 | if ( 'valid' !== key && field.validity[ key ] === true ) { |
| 1627 | 1436 | isInvalid = true; |
| 1628 | 1437 | break; |
| 1629 | 1438 | } |
| 1630 | - } | |
| 1439 | + }; | |
| 1631 | 1440 | |
| 1632 | 1441 | if ( ! isInvalid ) { |
| 1633 | 1442 | field.setCustomValidity( '' ); |
| 1634 | 1443 | } |
| @@ -1651,9 +1460,9 @@ | ||
| 1651 | 1460 | |
| 1652 | 1461 | function setCustomValidityMessage() { |
| 1653 | 1462 | let forms, length, index; |
| 1654 | 1463 | |
| 1655 | - forms = document.getElementsByClassName( 'frm-show-form' ); | |
| 1464 | + forms = document.getElementsByClassName( 'frm-show-form' ); | |
| 1656 | 1465 | length = forms.length; |
| 1657 | 1466 | |
| 1658 | 1467 | for ( index = 0; index < length; ++index ) { |
| 1659 | 1468 | forms[ index ].addEventListener( |
| @@ -1674,14 +1483,14 @@ | ||
| 1674 | 1483 | window.addEventListener( 'pageshow', function( event ) { |
| 1675 | 1484 | if ( event.persisted ) { |
| 1676 | 1485 | document.querySelectorAll( '.frm_loading_form' ).forEach( |
| 1677 | 1486 | function( form ) { |
| 1678 | - enableSubmitButton( form ); | |
| 1487 | + enableSubmitButton( jQuery( form ) ); | |
| 1679 | 1488 | } |
| 1680 | 1489 | ); |
| 1681 | 1490 | removeSubmitLoading(); |
| 1682 | 1491 | } |
| 1683 | - } ); | |
| 1492 | + }); | |
| 1684 | 1493 | } |
| 1685 | 1494 | |
| 1686 | 1495 | /** |
| 1687 | 1496 | * Destroys the formidable generated global hcaptcha object since it wouldn't otherwise render. |
| @@ -1692,88 +1501,23 @@ | ||
| 1692 | 1501 | } |
| 1693 | 1502 | window.hcaptcha = null; |
| 1694 | 1503 | } |
| 1695 | 1504 | |
| 1696 | - /** | |
| 1697 | - * @since 6.16.3 | |
| 1698 | - * | |
| 1699 | - * @return {string} Unique key, used for duplicate checks. | |
| 1700 | - */ | |
| 1701 | - function getUniqueKey() { | |
| 1702 | - const uniqueKey = Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) ) | |
| 1703 | - .map( b => b.toString( 16 ).padStart( 2, '0' ) ) | |
| 1704 | - .join( '' ); | |
| 1705 | - const timestamp = Date.now().toString( 16 ); | |
| 1706 | - return uniqueKey + '-' + timestamp; | |
| 1707 | - } | |
| 1708 | - | |
| 1709 | - /** | |
| 1710 | - * Animates the scroll position of the document. | |
| 1711 | - * | |
| 1712 | - * @since 6.20 | |
| 1713 | - * | |
| 1714 | - * @param {number} start | |
| 1715 | - * @param {number} end | |
| 1716 | - * @param {number} duration | |
| 1717 | - * @return {void} | |
| 1718 | - */ | |
| 1719 | - function animateScroll( start, end, duration ) { | |
| 1720 | - if ( ! window.hasOwnProperty( 'performance' ) || ! window.hasOwnProperty( 'requestAnimationFrame' ) ) { | |
| 1721 | - document.documentElement.scrollTop = end; | |
| 1722 | - return; | |
| 1723 | - } | |
| 1724 | - | |
| 1725 | - /* eslint-disable compat/compat */ | |
| 1726 | - const startTime = performance.now(); | |
| 1727 | - const step = currentTime => { | |
| 1728 | - const progress = Math.min( ( currentTime - startTime ) / duration, 1 ); | |
| 1729 | - document.documentElement.scrollTop = start + ( ( end - start ) * progress ); | |
| 1730 | - if ( progress < 1 ) { | |
| 1731 | - requestAnimationFrame( step ); | |
| 1732 | - } | |
| 1733 | - }; | |
| 1734 | - requestAnimationFrame( step ); | |
| 1735 | - /* eslint-enable compat/compat */ | |
| 1736 | - } | |
| 1737 | - | |
| 1738 | - /** | |
| 1739 | - * Make sure that the captcha label for a reCAPTCHA or Turnstile field matches the response input ID. | |
| 1740 | - * This is determined dynamically, so we check for the ID after the input is rendered. | |
| 1741 | - * hCaptcha is handled separately, in the frmCaptcha function as it is not rendered explicitly. | |
| 1742 | - * | |
| 1743 | - * @since 6.25.1 | |
| 1744 | - * | |
| 1745 | - * @param {HTMLElement} captcha | |
| 1746 | - * @return {void} | |
| 1747 | - */ | |
| 1748 | - function maybeFixCaptchaLabel( captcha ) { | |
| 1749 | - const form = captcha.closest( 'form' ); | |
| 1750 | - if ( ! form ) { | |
| 1751 | - return; | |
| 1752 | - } | |
| 1753 | - | |
| 1754 | - const label = form.querySelector( 'label[for="g-recaptcha-response"], label[for="cf-turnstile-response"]' ); | |
| 1755 | - const captchaResponse = form.querySelector( '[name="g-recaptcha-response"], [name="cf-turnstile-response"]' ); | |
| 1756 | - | |
| 1757 | - if ( label && captchaResponse ) { | |
| 1758 | - label.htmlFor = captchaResponse.id; | |
| 1759 | - } | |
| 1760 | - } | |
| 1761 | - | |
| 1762 | 1505 | return { |
| 1763 | 1506 | init: function() { |
| 1764 | 1507 | jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); |
| 1765 | 1508 | jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm ); |
| 1766 | 1509 | |
| 1767 | - document.querySelectorAll( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).forEach( function( field ) { | |
| 1768 | - if ( field.value === '' ) { | |
| 1769 | - jQuery( field ).trigger( 'blur' ); | |
| 1510 | + jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() { | |
| 1511 | + if ( jQuery( this ).val() === '' ) { | |
| 1512 | + jQuery( this ).trigger( 'blur' ); | |
| 1770 | 1513 | } |
| 1771 | - } ); | |
| 1514 | + }); | |
| 1772 | 1515 | |
| 1773 | 1516 | 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 ); |
| 1774 | 1517 | |
| 1775 | - jQuery( document ).on( 'change', '.frm_verify[id^=field_]', onHoneypotFieldChange ); | |
| 1518 | + jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange ); | |
| 1519 | + maybeMakeHoneypotFieldsUntabbable(); | |
| 1776 | 1520 | |
| 1777 | 1521 | jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick ); |
| 1778 | 1522 | |
| 1779 | 1523 | checkForErrorsAndMaybeSetFocus(); |
| @@ -1799,60 +1543,49 @@ | ||
| 1799 | 1543 | destroyhCaptcha |
| 1800 | 1544 | ); |
| 1801 | 1545 | }, |
| 1802 | 1546 | |
| 1803 | - getFieldId, | |
| 1547 | + getFieldId: function( field, fullID ) { | |
| 1548 | + return getFieldId( field, fullID ); | |
| 1549 | + }, | |
| 1804 | 1550 | |
| 1805 | - /** | |
| 1806 | - * Render a captcha field. | |
| 1807 | - * | |
| 1808 | - * @param {HTMLElement} captcha | |
| 1809 | - * @param {string} captchaSelector | |
| 1810 | - * @return {void} | |
| 1811 | - */ | |
| 1812 | 1551 | renderCaptcha: function( captcha, captchaSelector ) { |
| 1813 | - const rendered = captcha.getAttribute( 'data-rid' ) !== null; | |
| 1552 | + let formID, captchaID, | |
| 1553 | + size = captcha.getAttribute( 'data-size' ), | |
| 1554 | + rendered = captcha.getAttribute( 'data-rid' ) !== null, | |
| 1555 | + params = { | |
| 1556 | + 'sitekey': captcha.getAttribute( 'data-sitekey' ), | |
| 1557 | + 'size': size, | |
| 1558 | + 'theme': captcha.getAttribute( 'data-theme' ) | |
| 1559 | + }, | |
| 1560 | + activeCaptcha = getSelectedCaptcha( captchaSelector ), | |
| 1561 | + captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? '#' + captcha.id : captcha.id; | |
| 1562 | + | |
| 1814 | 1563 | if ( rendered ) { |
| 1815 | 1564 | return; |
| 1816 | 1565 | } |
| 1817 | 1566 | |
| 1818 | - const size = captcha.getAttribute( 'data-size' ); | |
| 1819 | - const params = { | |
| 1820 | - sitekey: captcha.getAttribute( 'data-sitekey' ), | |
| 1821 | - size: size, | |
| 1822 | - theme: captcha.getAttribute( 'data-theme' ) | |
| 1823 | - }; | |
| 1824 | - | |
| 1825 | 1567 | if ( size === 'invisible' ) { |
| 1826 | - const formID = captcha.closest( 'form' )?.querySelector( 'input[name="form_id"]' )?.value; | |
| 1827 | - | |
| 1828 | - const captchaLabel = captcha.closest( '.frm_form_field' )?.querySelector( '.frm_primary_label' ); | |
| 1829 | - if ( captchaLabel ) { | |
| 1830 | - captchaLabel.style.display = 'none'; | |
| 1831 | - } | |
| 1832 | - | |
| 1568 | + formID = jQuery( captcha ).closest( 'form' ).find( 'input[name="form_id"]' ).val(); | |
| 1569 | + jQuery( captcha ).closest( '.frm_form_field .frm_primary_label' ).hide(); | |
| 1833 | 1570 | params.callback = function( token ) { |
| 1834 | 1571 | frmFrontForm.afterRecaptcha( token, formID ); |
| 1835 | 1572 | }; |
| 1836 | 1573 | } |
| 1837 | 1574 | |
| 1838 | - const activeCaptcha = getSelectedCaptcha( captchaSelector ); | |
| 1839 | - const captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? '#' + captcha.id : captcha.id; | |
| 1840 | - const captchaID = activeCaptcha.render( captchaContainer, params ); | |
| 1841 | 1575 | |
| 1576 | + captchaID = activeCaptcha.render( captchaContainer, params ); | |
| 1577 | + | |
| 1842 | 1578 | captcha.setAttribute( 'data-rid', captchaID ); |
| 1843 | - | |
| 1844 | - maybeFixCaptchaLabel( captcha ); | |
| 1845 | 1579 | }, |
| 1846 | 1580 | |
| 1847 | 1581 | afterSingleRecaptcha: function() { |
| 1848 | - const recaptcha = document.querySelector( '.frm-show-form .g-recaptcha' ); | |
| 1849 | - const object = recaptcha ? recaptcha.closest( 'form' ) : null; | |
| 1582 | + const object = jQuery( '.frm-show-form .g-recaptcha' ).closest( 'form' )[0]; | |
| 1850 | 1583 | frmFrontForm.submitFormNow( object ); |
| 1851 | 1584 | }, |
| 1852 | 1585 | |
| 1853 | 1586 | afterRecaptcha: function( _, formID ) { |
| 1854 | - const object = document.querySelector( '#frm_form_' + formID + '_container form' ); | |
| 1587 | + const object = jQuery( '#frm_form_' + formID + '_container form' )[0]; | |
| 1855 | 1588 | frmFrontForm.submitFormNow( object ); |
| 1856 | 1589 | }, |
| 1857 | 1590 | |
| 1858 | 1591 | submitForm: function( e ) { |
| @@ -1864,9 +1597,20 @@ | ||
| 1864 | 1597 | * @param {HTMLElement} object The form object that is being submitted. |
| 1865 | 1598 | * @return {void} |
| 1866 | 1599 | */ |
| 1867 | 1600 | submitFormManual: function( e, object ) { |
| 1868 | - if ( document.body.classList.contains( 'wp-admin' ) && ! object.closest( '.frmapi-form' ) ) { | |
| 1601 | + let isPro, errors, | |
| 1602 | + invisibleRecaptcha = hasInvisibleRecaptcha( object ), | |
| 1603 | + classList = object.className.trim().split( /\s+/gi ); | |
| 1604 | + | |
| 1605 | + if ( classList && invisibleRecaptcha.length < 1 ) { | |
| 1606 | + isPro = classList.indexOf( 'frm_pro_form' ) > -1; | |
| 1607 | + if ( ! isPro ) { | |
| 1608 | + return; | |
| 1609 | + } | |
| 1610 | + } | |
| 1611 | + | |
| 1612 | + if ( jQuery( 'body' ).hasClass( 'wp-admin' ) && jQuery( object ).closest( '.frmapi-form' ).length < 1 ) { | |
| 1869 | 1613 | return; |
| 1870 | 1614 | } |
| 1871 | 1615 | |
| 1872 | 1616 | e.preventDefault(); |
| @@ -1874,22 +1618,21 @@ | ||
| 1874 | 1618 | if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' && ! frmProForm.submitAllowed( object ) ) { |
| 1875 | 1619 | return; |
| 1876 | 1620 | } |
| 1877 | 1621 | |
| 1878 | - const errors = frmFrontForm.validateFormSubmit( object ); | |
| 1622 | + errors = frmFrontForm.validateFormSubmit( object ); | |
| 1879 | 1623 | if ( Object.keys( errors ).length !== 0 ) { |
| 1880 | 1624 | return; |
| 1881 | 1625 | } |
| 1882 | 1626 | |
| 1883 | - const invisibleRecaptcha = hasInvisibleRecaptcha( object ); | |
| 1884 | - | |
| 1885 | - if ( invisibleRecaptcha ) { | |
| 1627 | + if ( invisibleRecaptcha.length ) { | |
| 1886 | 1628 | showLoadingIndicator( jQuery( object ) ); |
| 1887 | 1629 | executeInvisibleRecaptcha( invisibleRecaptcha ); |
| 1888 | 1630 | } else { |
| 1631 | + | |
| 1889 | 1632 | showSubmitLoading( jQuery( object ) ); |
| 1890 | 1633 | |
| 1891 | - frmFrontForm.submitFormNow( object ); | |
| 1634 | + frmFrontForm.submitFormNow( object, classList ); | |
| 1892 | 1635 | } |
| 1893 | 1636 | }, |
| 1894 | 1637 | |
| 1895 | 1638 | submitFormNow: function( object ) { |
| @@ -1904,21 +1647,14 @@ | ||
| 1904 | 1647 | antispamInput.value = object.getAttribute( 'data-token' ); |
| 1905 | 1648 | object.appendChild( antispamInput ); |
| 1906 | 1649 | } |
| 1907 | 1650 | |
| 1908 | - // Add a unique ID, used for duplicate checks. | |
| 1909 | - const uniqueIDInput = document.createElement( 'input' ); | |
| 1910 | - uniqueIDInput.type = 'hidden'; | |
| 1911 | - uniqueIDInput.name = 'unique_id'; | |
| 1912 | - uniqueIDInput.value = getUniqueKey(); | |
| 1913 | - object.appendChild( uniqueIDInput ); | |
| 1914 | - | |
| 1915 | 1651 | if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) { |
| 1916 | - const fileInputs = object.querySelectorAll( 'input[type="file"]' ); | |
| 1917 | - hasFileFields = Array.from( fileInputs ).filter( input => !! input.value ).length; | |
| 1652 | + hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() { | |
| 1653 | + return !! this.value; | |
| 1654 | + }).length; | |
| 1918 | 1655 | if ( hasFileFields < 1 ) { |
| 1919 | - const actionInput = object.querySelector( 'input[name="frm_action"]' ); | |
| 1920 | - const action = actionInput ? actionInput.value : ''; | |
| 1656 | + action = jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 1921 | 1657 | frmFrontForm.checkFormErrors( object, action ); |
| 1922 | 1658 | } else { |
| 1923 | 1659 | object.submit(); |
| 1924 | 1660 | } |
| @@ -1932,10 +1668,9 @@ | ||
| 1932 | 1668 | * |
| 1933 | 1669 | * @return {Array} List of errors. |
| 1934 | 1670 | */ |
| 1935 | 1671 | validateFormSubmit: function( object ) { |
| 1936 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1937 | - if ( typeof tinyMCE !== 'undefined' && form && form.querySelector( '.wp-editor-wrap' ) ) { | |
| 1672 | + if ( typeof tinyMCE !== 'undefined' && jQuery( object ).find( '.wp-editor-wrap' ).length ) { | |
| 1938 | 1673 | tinyMCE.triggerSave(); |
| 1939 | 1674 | } |
| 1940 | 1675 | |
| 1941 | 1676 | jsErrors = []; |
| @@ -1956,16 +1691,14 @@ | ||
| 1956 | 1691 | * @return {Array} List of errors. |
| 1957 | 1692 | */ |
| 1958 | 1693 | getAjaxFormErrors: function( object ) { |
| 1959 | 1694 | let customErrors, key; |
| 1960 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1961 | 1695 | |
| 1962 | 1696 | jsErrors = validateForm( object ); |
| 1963 | 1697 | if ( typeof frmThemeOverride_jsErrors === 'function' ) { // eslint-disable-line camelcase |
| 1964 | - const actionInput = form ? form.querySelector( 'input[name="frm_action"]' ) : null; | |
| 1965 | - const action = actionInput ? actionInput.value : ''; | |
| 1698 | + action = jQuery( object ).find( 'input[name="frm_action"]' ).val(); | |
| 1966 | 1699 | customErrors = frmThemeOverride_jsErrors( action, object ); |
| 1967 | - if ( Object.keys( customErrors ).length ) { | |
| 1700 | + if ( Object.keys( customErrors ).length ) { | |
| 1968 | 1701 | for ( key in customErrors ) { |
| 1969 | 1702 | jsErrors[ key ] = customErrors[ key ]; |
| 1970 | 1703 | } |
| 1971 | 1704 | } |
| @@ -1973,9 +1706,9 @@ | ||
| 1973 | 1706 | |
| 1974 | 1707 | triggerCustomEvent( document, 'frm_get_ajax_form_errors', { |
| 1975 | 1708 | formEl: object, |
| 1976 | 1709 | errors: jsErrors |
| 1977 | - } ); | |
| 1710 | + }); | |
| 1978 | 1711 | |
| 1979 | 1712 | return jsErrors; |
| 1980 | 1713 | }, |
| 1981 | 1714 | |
| @@ -1983,17 +1716,16 @@ | ||
| 1983 | 1716 | * @param {HTMLElement|Object} object Form object. This might be a jQuery object. |
| 1984 | 1717 | * @return {void} |
| 1985 | 1718 | */ |
| 1986 | 1719 | addAjaxFormErrors: function( object ) { |
| 1987 | - let key; | |
| 1988 | - const form = object instanceof jQuery ? object.get( 0 ) : object; | |
| 1720 | + let key, $fieldCont; | |
| 1989 | 1721 | removeAllErrors(); |
| 1990 | 1722 | |
| 1991 | 1723 | for ( key in jsErrors ) { |
| 1992 | - const fieldCont = form ? form.querySelector( '#frm_field_' + key + '_container' ) : null; | |
| 1724 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 1993 | 1725 | |
| 1994 | - if ( fieldCont ) { | |
| 1995 | - addFieldError( fieldCont, key, jsErrors ); | |
| 1726 | + if ( $fieldCont.length ) { | |
| 1727 | + addFieldError( $fieldCont, key, jsErrors ); | |
| 1996 | 1728 | } else { |
| 1997 | 1729 | // we are unable to show the error, so remove it |
| 1998 | 1730 | delete jsErrors[ key ]; |
| 1999 | 1731 | } |
| @@ -2002,13 +1734,24 @@ | ||
| 2002 | 1734 | scrollToFirstField( object ); |
| 2003 | 1735 | checkForErrorsAndMaybeSetFocus(); |
| 2004 | 1736 | }, |
| 2005 | 1737 | |
| 2006 | - checkFormErrors: getFormErrors, | |
| 2007 | - checkRequiredField, | |
| 2008 | - showSubmitLoading, | |
| 2009 | - removeSubmitLoading, | |
| 1738 | + checkFormErrors: function( object, action ) { | |
| 1739 | + getFormErrors( object, action ); | |
| 1740 | + }, | |
| 2010 | 1741 | |
| 1742 | + checkRequiredField: function( field, errors ) { | |
| 1743 | + return checkRequiredField( field, errors ); | |
| 1744 | + }, | |
| 1745 | + | |
| 1746 | + showSubmitLoading: function( $object ) { | |
| 1747 | + showSubmitLoading( $object ); | |
| 1748 | + }, | |
| 1749 | + | |
| 1750 | + removeSubmitLoading: function( $object, enable, processesRunning ) { | |
| 1751 | + removeSubmitLoading( $object, enable, processesRunning ); | |
| 1752 | + }, | |
| 1753 | + | |
| 2011 | 1754 | scrollToID: function( id ) { |
| 2012 | 1755 | const object = jQuery( document.getElementById( id ) ); |
| 2013 | 1756 | frmFrontForm.scrollMsg( object, false ); |
| 2014 | 1757 | }, |
| @@ -2021,11 +1764,9 @@ | ||
| 2021 | 1764 | if ( scrollObj.length < 1 ) { |
| 2022 | 1765 | return; |
| 2023 | 1766 | } |
| 2024 | 1767 | } else if ( typeof id === 'string' ) { |
| 2025 | - const formEl = object instanceof jQuery ? object.get( 0 ) : object; | |
| 2026 | - const fieldEl = formEl ? formEl.querySelector( '#frm_field_' + id + '_container' ) : null; | |
| 2027 | - scrollObj = fieldEl ? jQuery( fieldEl ) : jQuery(); | |
| 1768 | + scrollObj = jQuery( object ).find( '#frm_field_' + id + '_container' ); | |
| 2028 | 1769 | } else { |
| 2029 | 1770 | scrollObj = id; |
| 2030 | 1771 | } |
| 2031 | 1772 | |
| @@ -2035,10 +1776,10 @@ | ||
| 2035 | 1776 | return; |
| 2036 | 1777 | } |
| 2037 | 1778 | newPos = newPos - frm_js.offset; // eslint-disable-line camelcase |
| 2038 | 1779 | |
| 2039 | - m = getComputedStyle( document.documentElement ).marginTop; | |
| 2040 | - b = getComputedStyle( document.body ).marginTop; | |
| 1780 | + m = jQuery( 'html' ).css( 'margin-top' ); | |
| 1781 | + b = jQuery( 'body' ).css( 'margin-top' ); | |
| 2041 | 1782 | if ( m || b ) { |
| 2042 | 1783 | newPos = newPos - parseInt( m ) - parseInt( b ); |
| 2043 | 1784 | } |
| 2044 | 1785 | |
| @@ -2048,11 +1789,11 @@ | ||
| 2048 | 1789 | |
| 2049 | 1790 | if ( newPos > screenBottom || newPos < screenTop ) { |
| 2050 | 1791 | // Not in view |
| 2051 | 1792 | if ( typeof animate === 'undefined' ) { |
| 2052 | - document.documentElement.scrollTop = newPos; | |
| 1793 | + jQuery( window ).scrollTop( newPos ); | |
| 2053 | 1794 | } else { |
| 2054 | - animateScroll( screenTop, newPos, 500 ); | |
| 1795 | + jQuery( 'html,body' ).animate({ scrollTop: newPos }, 500 ); | |
| 2055 | 1796 | } |
| 2056 | 1797 | return false; |
| 2057 | 1798 | } |
| 2058 | 1799 | } |
| @@ -2069,9 +1810,9 @@ | ||
| 2069 | 1810 | if ( e.frmTriggered && e.frmTriggered == fieldId ) { |
| 2070 | 1811 | return; |
| 2071 | 1812 | } |
| 2072 | 1813 | |
| 2073 | - jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ] ); | |
| 1814 | + jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]); | |
| 2074 | 1815 | |
| 2075 | 1816 | if ( e.selfTriggered !== true ) { |
| 2076 | 1817 | maybeValidateChange( this ); |
| 2077 | 1818 | } |
| @@ -2077,9 +1818,8 @@ | ||
| 2077 | 1818 | } |
| 2078 | 1819 | }, |
| 2079 | 1820 | |
| 2080 | 1821 | escapeHtml: function( text ) { |
| 2081 | - console.warn( 'DEPRECATED: function frmFrontForm.escapeHtml in v6.17' ); | |
| 2082 | 1822 | return text |
| 2083 | 1823 | .replace( /&/g, '&' ) |
| 2084 | 1824 | .replace( /</g, '<' ) |
| 2085 | 1825 | .replace( />/g, '>' ) |
| @@ -2086,8 +1826,16 @@ | ||
| 2086 | 1826 | .replace( /"/g, '"' ) |
| 2087 | 1827 | .replace( /'/g, ''' ); |
| 2088 | 1828 | }, |
| 2089 | 1829 | |
| 1830 | + invisible: function( classes ) { | |
| 1831 | + jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 1832 | + }, | |
| 1833 | + | |
| 1834 | + visible: function( classes ) { | |
| 1835 | + jQuery( classes ).css( 'visibility', 'visible' ); | |
| 1836 | + }, | |
| 1837 | + | |
| 2090 | 1838 | triggerCustomEvent: triggerCustomEvent, |
| 2091 | 1839 | documentOn |
| 2092 | 1840 | }; |
| 2093 | 1841 | } |
| @@ -2095,45 +1843,26 @@ | ||
| 2095 | 1843 | window.frmFrontForm = frmFrontFormJS(); |
| 2096 | 1844 | |
| 2097 | 1845 | jQuery( document ).ready( function() { |
| 2098 | 1846 | frmFrontForm.init(); |
| 2099 | -} ); | |
| 1847 | +}); | |
| 2100 | 1848 | |
| 2101 | 1849 | function frmRecaptcha() { |
| 2102 | 1850 | frmCaptcha( '.frm-g-recaptcha' ); |
| 2103 | 1851 | } |
| 2104 | 1852 | |
| 2105 | -function frmHcaptcha() { | |
| 2106 | - frmCaptcha( '.h-captcha' ); | |
| 2107 | -} | |
| 2108 | - | |
| 2109 | 1853 | function frmTurnstile() { |
| 2110 | - frmCaptcha( '.frm-cf-turnstile' ); | |
| 1854 | + frmCaptcha( '.cf-turnstile' ); | |
| 2111 | 1855 | } |
| 2112 | 1856 | |
| 2113 | 1857 | function frmCaptcha( captchaSelector ) { |
| 2114 | - if ( '.h-captcha' === captchaSelector ) { | |
| 2115 | - // hCaptcha is still rendered implicitly, so we only want to handle the label and exit early. | |
| 2116 | - // Match the hcaptcha labels to the hcaptcha response fields. | |
| 2117 | - const captchaLabels = document.querySelectorAll( 'label[for="h-captcha-response"]' ); | |
| 2118 | - if ( captchaLabels.length ) { | |
| 2119 | - captchaLabels.forEach( label => { | |
| 2120 | - const captchaResponse = label.closest( 'form' )?.querySelector( '[name="h-captcha-response"]' ); | |
| 2121 | - if ( captchaResponse ) { | |
| 2122 | - label.htmlFor = captchaResponse.id; | |
| 2123 | - } | |
| 2124 | - } ); | |
| 2125 | - } | |
| 2126 | - return; | |
| 2127 | - } | |
| 2128 | - | |
| 2129 | 1858 | let c; |
| 2130 | 1859 | const captchas = document.querySelectorAll( captchaSelector ); |
| 2131 | - const cl = captchas.length; | |
| 1860 | + const cl = captchas.length; | |
| 2132 | 1861 | for ( c = 0; c < cl; c++ ) { |
| 2133 | - const closestForm = captchas[ c ].closest( 'form' ); | |
| 1862 | + const closestForm = captchas[c].closest( 'form' ); | |
| 2134 | 1863 | const formIsVisible = closestForm && closestForm.offsetParent !== null; |
| 2135 | - const captcha = captchas[ c ]; | |
| 1864 | + const captcha = captchas[c]; | |
| 2136 | 1865 | if ( ! formIsVisible ) { |
| 2137 | 1866 | // If the form is not visible, try again later in 400ms. |
| 2138 | 1867 | // This fixes issues where the form fades visible on page load. |
| 2139 | 1868 | // Or whne the form is inside of a modal. |
| @@ -2155,9 +1884,9 @@ | ||
| 2155 | 1884 | function getSelectedCaptcha( captchaSelector ) { |
| 2156 | 1885 | if ( captchaSelector === '.frm-g-recaptcha' ) { |
| 2157 | 1886 | return grecaptcha; |
| 2158 | 1887 | } |
| 2159 | - if ( document.querySelector( '.frm-cf-turnstile' ) ) { | |
| 1888 | + if ( document.querySelector( '.cf-turnstile' ) ) { | |
| 2160 | 1889 | return turnstile; |
| 2161 | 1890 | } |
| 2162 | 1891 | return hcaptcha; |
| 2163 | 1892 | } |