| @@ -10,70 +10,19 @@ | ||
| 10 | 10 | |
| 11 | 11 | var action = ''; |
| 12 | 12 | var jsErrors = []; |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * Maybe add polyfills. | |
| 16 | - * | |
| 17 | - * @since 5.4 | |
| 18 | - */ | |
| 19 | - function maybeAddPolyfills() { | |
| 20 | - var i; | |
| 21 | - if ( ! Element.prototype.matches ) { | |
| 22 | - // IE9 supports matches but as msMatchesSelector instead. | |
| 23 | - Element.prototype.matches = Element.prototype.msMatchesSelector; | |
| 24 | - } | |
| 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(); | |
| 25 | 19 | |
| 26 | - if ( ! Element.prototype.closest ) { | |
| 27 | - Element.prototype.closest = function( s ) { | |
| 28 | - var el = this; | |
| 29 | - | |
| 30 | - do { | |
| 31 | - if ( el.matches( s ) ) { | |
| 32 | - return el; | |
| 33 | - } | |
| 34 | - el = el.parentElement || el.parentNode; | |
| 35 | - } while ( el !== null && el.nodeType === 1 ); | |
| 36 | - | |
| 37 | - return null; | |
| 38 | - }; | |
| 39 | - } | |
| 40 | - | |
| 41 | - // NodeList.forEach(). | |
| 42 | - if ( window.NodeList && ! NodeList.prototype.forEach ) { | |
| 43 | - NodeList.prototype.forEach = function( callback, thisArg ) { | |
| 44 | - thisArg = thisArg || window; | |
| 45 | - for ( i = 0; i < this.length; i++ ) { | |
| 46 | - callback.call( thisArg, this[ i ], i, this ); | |
| 47 | - } | |
| 48 | - }; | |
| 49 | - } | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Triggers custom JS event. | |
| 54 | - * | |
| 55 | - * @since 5.5.3 | |
| 56 | - * | |
| 57 | - * @param {HTMLElement} el The HTML element. | |
| 58 | - * @param {String} eventName Event name. | |
| 59 | - * @param {mixed} data The passed data. | |
| 60 | - */ | |
| 61 | - function triggerCustomEvent( el, eventName, data ) { | |
| 62 | - var event; | |
| 63 | - | |
| 64 | - if ( typeof window.CustomEvent === 'function' ) { | |
| 65 | - event = new CustomEvent( eventName ); | |
| 66 | - } else if ( document.createEvent ) { | |
| 67 | - event = document.createEvent( 'HTMLEvents' ); | |
| 68 | - event.initEvent( eventName, false, true ); | |
| 20 | + if ( val !== null && val.length > 0 ) { | |
| 21 | + $label.addClass( 'frm_visible' ); | |
| 69 | 22 | } else { |
| 70 | - return; | |
| 23 | + $label.removeClass( 'frm_visible' ); | |
| 71 | 24 | } |
| 72 | - | |
| 73 | - event.frmData = data; | |
| 74 | - | |
| 75 | - el.dispatchEvent( event ); | |
| 76 | 25 | } |
| 77 | 26 | |
| 78 | 27 | /* Get the ID of the field that changed*/ |
| 79 | 28 | function getFieldId( field, fullID ) { |
| @@ -162,9 +111,9 @@ | ||
| 162 | 111 | * |
| 163 | 112 | * @since 2.03.02 |
| 164 | 113 | * |
| 165 | 114 | * @param {object} $form |
| 166 | - */ | |
| 115 | + */ | |
| 167 | 116 | function disableSubmitButton( $form ) { |
| 168 | 117 | $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).attr( 'disabled', 'disabled' ); |
| 169 | 118 | } |
| 170 | 119 | |
| @@ -173,9 +122,9 @@ | ||
| 173 | 122 | * |
| 174 | 123 | * @since 2.03.02 |
| 175 | 124 | * |
| 176 | 125 | * @param {object} $form |
| 177 | - */ | |
| 126 | + */ | |
| 178 | 127 | function enableSubmitButton( $form ) { |
| 179 | 128 | $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false ); |
| 180 | 129 | } |
| 181 | 130 | |
| @@ -201,12 +150,11 @@ | ||
| 201 | 150 | $form.find( 'a.frm_save_draft' ).css( 'pointer-events', '' ); |
| 202 | 151 | } |
| 203 | 152 | |
| 204 | 153 | function validateForm( object ) { |
| 205 | - var errors, r, rl, n, nl, fields, field, requiredFields; | |
| 154 | + var r, rl, n, nl, fields, field, value, requiredFields, | |
| 155 | + errors = []; | |
| 206 | 156 | |
| 207 | - errors = []; | |
| 208 | - | |
| 209 | 157 | // Make sure required text field is filled in |
| 210 | 158 | requiredFields = jQuery( object ).find( |
| 211 | 159 | '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea' |
| 212 | 160 | ).filter( ':not(.frm_optional)' ); |
| @@ -211,12 +159,8 @@ | ||
| 211 | 159 | '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea' |
| 212 | 160 | ).filter( ':not(.frm_optional)' ); |
| 213 | 161 | if ( requiredFields.length ) { |
| 214 | 162 | for ( r = 0, rl = requiredFields.length; r < rl; r++ ) { |
| 215 | - if ( hasClass( requiredFields[r], 'ed_button' ) ) { | |
| 216 | - // skip rich text field buttons. | |
| 217 | - continue; | |
| 218 | - } | |
| 219 | 163 | errors = checkRequiredField( requiredFields[r], errors ); |
| 220 | 164 | } |
| 221 | 165 | } |
| 222 | 166 | |
| @@ -223,18 +167,24 @@ | ||
| 223 | 167 | fields = jQuery( object ).find( 'input,select,textarea' ); |
| 224 | 168 | if ( fields.length ) { |
| 225 | 169 | for ( n = 0, nl = fields.length; n < nl; n++ ) { |
| 226 | 170 | field = fields[n]; |
| 227 | - if ( '' === field.value ) { | |
| 228 | - if ( 'number' === field.type ) { | |
| 229 | - // A number field will return an empty string when it is invalid. | |
| 230 | - checkValidity( field, errors ); | |
| 171 | + value = field.value; | |
| 172 | + if ( value !== '' ) { | |
| 173 | + if ( field.type === 'hidden' ) { | |
| 174 | + // don't validate | |
| 175 | + } else if ( field.type === 'number' ) { | |
| 176 | + errors = checkNumberField( field, errors ); | |
| 177 | + } else if ( field.type === 'email' ) { | |
| 178 | + errors = checkEmailField( field, errors ); | |
| 179 | + } else if ( field.type === 'password' ) { | |
| 180 | + errors = checkPasswordField( field, errors ); | |
| 181 | + } else if ( field.type === 'url' ) { | |
| 182 | + errors = checkUrlField( field, errors ); | |
| 183 | + } else if ( field.pattern !== null ) { | |
| 184 | + errors = checkPatternField( field, errors ); | |
| 231 | 185 | } |
| 232 | - continue; | |
| 233 | 186 | } |
| 234 | - | |
| 235 | - validateFieldValue( field, errors ); | |
| 236 | - checkValidity( field, errors ); | |
| 237 | 187 | } |
| 238 | 188 | } |
| 239 | 189 | |
| 240 | 190 | errors = validateRecaptcha( object, errors ); |
| @@ -241,51 +191,14 @@ | ||
| 241 | 191 | |
| 242 | 192 | return errors; |
| 243 | 193 | } |
| 244 | 194 | |
| 245 | - /** | |
| 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 | - * @returns | |
| 252 | - */ | |
| 253 | - function checkValidity( field, errors ) { | |
| 254 | - var 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 | - * @since 5.0.10 | |
| 272 | - * | |
| 273 | - * @param {object} element | |
| 274 | - * @param {string} targetClass | |
| 275 | - * @returns {boolean} | |
| 276 | - */ | |
| 277 | - function hasClass( element, targetClass ) { | |
| 278 | - var className = ' ' + element.className + ' '; | |
| 279 | - return -1 !== className.indexOf( ' ' + targetClass + ' ' ); | |
| 280 | - } | |
| 281 | - | |
| 282 | - function maybeValidateChange( field ) { | |
| 195 | + function maybeValidateChange( fieldId, field ) { | |
| 283 | 196 | if ( field.type === 'url' ) { |
| 284 | 197 | maybeAddHttpToUrl( field ); |
| 285 | 198 | } |
| 286 | 199 | if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) { |
| 287 | - validateField( field ); | |
| 200 | + validateField( fieldId, field ); | |
| 288 | 201 | } |
| 289 | 202 | } |
| 290 | 203 | |
| 291 | 204 | function maybeAddHttpToUrl( field ) { |
| @@ -295,19 +208,29 @@ | ||
| 295 | 208 | field.value = 'http://' + url; |
| 296 | 209 | } |
| 297 | 210 | } |
| 298 | 211 | |
| 299 | - function validateField( field ) { | |
| 212 | + function validateField( fieldId, field ) { | |
| 300 | 213 | var key, |
| 301 | - errors = [], | |
| 302 | - $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 214 | + errors = []; | |
| 303 | 215 | |
| 216 | + var $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 304 | 217 | if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) { |
| 305 | 218 | errors = checkRequiredField( field, errors ); |
| 306 | 219 | } |
| 307 | 220 | |
| 308 | 221 | if ( errors.length < 1 ) { |
| 309 | - validateFieldValue( field, errors ); | |
| 222 | + if ( field.type === 'email' ) { | |
| 223 | + errors = checkEmailField( field, errors ); | |
| 224 | + } else if ( field.type === 'password' ) { | |
| 225 | + errors = checkPasswordField( field, errors ); | |
| 226 | + } else if ( field.type === 'number' ) { | |
| 227 | + errors = checkNumberField( field, errors ); | |
| 228 | + } else if ( field.type === 'url' ) { | |
| 229 | + errors = checkUrlField( field, errors ); | |
| 230 | + } else if ( field.pattern !== null ) { | |
| 231 | + errors = checkPatternField( field, errors ); | |
| 232 | + } | |
| 310 | 233 | } |
| 311 | 234 | |
| 312 | 235 | removeFieldError( $fieldCont ); |
| 313 | 236 | if ( Object.keys( errors ).length > 0 ) { |
| @@ -316,36 +239,15 @@ | ||
| 316 | 239 | } |
| 317 | 240 | } |
| 318 | 241 | } |
| 319 | 242 | |
| 320 | - function validateFieldValue( field, errors ) { | |
| 321 | - if ( field.type === 'hidden' ) { | |
| 322 | - // don't validate | |
| 323 | - } else if ( field.type === 'number' ) { | |
| 324 | - checkNumberField( field, errors ); | |
| 325 | - } else if ( field.type === 'email' ) { | |
| 326 | - checkEmailField( field, errors ); | |
| 327 | - } else if ( field.type === 'password' ) { | |
| 328 | - checkPasswordField( field, errors ); | |
| 329 | - } else if ( field.type === 'url' ) { | |
| 330 | - checkUrlField( field, errors ); | |
| 331 | - } else if ( field.pattern !== null ) { | |
| 332 | - checkPatternField( field, errors ); | |
| 333 | - } | |
| 334 | - | |
| 335 | - triggerCustomEvent( document, 'frm_validate_field_value', { | |
| 336 | - field: field, | |
| 337 | - errors: errors | |
| 338 | - }); | |
| 339 | - } | |
| 340 | - | |
| 341 | 243 | function checkRequiredField( field, errors ) { |
| 342 | - var checkGroup, tempVal, i, placeholder, | |
| 244 | + var checkGroup, fieldClasses, tempVal, i, placeholder, | |
| 343 | 245 | val = '', |
| 344 | 246 | fieldID = '', |
| 345 | 247 | fileID = field.getAttribute( 'data-frmfile' ); |
| 346 | 248 | |
| 347 | - if ( field.type === 'hidden' && fileID === null && ! isAppointmentField( field ) && ! isInlineDatepickerField( field ) ) { | |
| 249 | + if ( field.type === 'hidden' && fileID === null ) { | |
| 348 | 250 | return errors; |
| 349 | 251 | } |
| 350 | 252 | |
| 351 | 253 | if ( field.type === 'checkbox' || field.type === 'radio' ) { |
| @@ -363,9 +265,10 @@ | ||
| 363 | 265 | val = getFileVals( fileID ); |
| 364 | 266 | } |
| 365 | 267 | fieldID = fileID; |
| 366 | 268 | } else { |
| 367 | - if ( hasClass( field, 'frm_pos_none' ) ) { | |
| 269 | + fieldClasses = field.className; | |
| 270 | + if ( fieldClasses.indexOf( 'frm_pos_none' ) !== -1 ) { | |
| 368 | 271 | // skip hidden other fields |
| 369 | 272 | return errors; |
| 370 | 273 | } |
| 371 | 274 | |
| @@ -381,26 +284,17 @@ | ||
| 381 | 284 | } |
| 382 | 285 | } |
| 383 | 286 | } |
| 384 | 287 | |
| 385 | - if ( hasClass( field, 'frm_other_input' ) ) { | |
| 288 | + if ( fieldClasses.indexOf( 'frm_other_input' ) === -1 ) { | |
| 289 | + fieldID = getFieldId( field, true ); | |
| 290 | + } else { | |
| 386 | 291 | fieldID = getFieldId( field, false ); |
| 387 | - | |
| 388 | - if ( val === '' ) { | |
| 389 | - field = document.getElementById( field.id.replace( '-otext', '' ) ); | |
| 390 | - } | |
| 391 | - } else { | |
| 392 | - fieldID = getFieldId( field, true ); | |
| 393 | 292 | } |
| 394 | 293 | |
| 395 | - if ( hasClass( field, 'frm_time_select' ) ) { | |
| 294 | + if ( fieldClasses.indexOf( 'frm_time_select' ) !== -1 ) { | |
| 396 | 295 | // set id for time field |
| 397 | 296 | fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' ); |
| 398 | - } else if ( isSignatureField( field ) ) { | |
| 399 | - if ( val === '' ) { | |
| 400 | - val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val(); | |
| 401 | - } | |
| 402 | - fieldID = fieldID.replace( '-typed', '' ); | |
| 403 | 297 | } |
| 404 | 298 | |
| 405 | 299 | placeholder = field.getAttribute( 'data-frmplaceholder' ); |
| 406 | 300 | if ( placeholder !== null && val === placeholder ) { |
| @@ -419,21 +313,8 @@ | ||
| 419 | 313 | |
| 420 | 314 | return errors; |
| 421 | 315 | } |
| 422 | 316 | |
| 423 | - function isSignatureField( field ) { | |
| 424 | - var name = field.getAttribute( 'name' ); | |
| 425 | - return 'string' === typeof name && '[typed]' === name.substr( -7 ); | |
| 426 | - } | |
| 427 | - | |
| 428 | - function isAppointmentField( field ) { | |
| 429 | - return hasClass( field, 'ssa_appointment_form_field_appointment_id' ); | |
| 430 | - } | |
| 431 | - | |
| 432 | - function isInlineDatepickerField( field ) { | |
| 433 | - return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' ); | |
| 434 | - } | |
| 435 | - | |
| 436 | 317 | function getFileVals( fileID ) { |
| 437 | 318 | var val = '', |
| 438 | 319 | fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); |
| 439 | 320 | |
| @@ -454,8 +335,9 @@ | ||
| 454 | 335 | if ( ! ( fieldID in errors ) ) { |
| 455 | 336 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 456 | 337 | } |
| 457 | 338 | } |
| 339 | + return errors; | |
| 458 | 340 | } |
| 459 | 341 | |
| 460 | 342 | function checkEmailField( field, errors ) { |
| 461 | 343 | var fieldID = getFieldId( field, true ), |
| @@ -466,12 +348,14 @@ | ||
| 466 | 348 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 467 | 349 | } |
| 468 | 350 | |
| 469 | 351 | confirmField( field, errors ); |
| 352 | + return errors; | |
| 470 | 353 | } |
| 471 | 354 | |
| 472 | 355 | function checkPasswordField( field, errors ) { |
| 473 | 356 | confirmField( field, errors ); |
| 357 | + return errors; | |
| 474 | 358 | } |
| 475 | 359 | |
| 476 | 360 | function confirmField( field, errors ) { |
| 477 | 361 | var value, confirmValue, firstField, |
| @@ -491,9 +375,9 @@ | ||
| 491 | 375 | if ( '' !== value && '' !== confirmValue && value !== confirmValue ) { |
| 492 | 376 | errors[ 'conf_' + strippedFieldID ] = getFieldValidationMessage( confirmField, 'data-confmsg' ); |
| 493 | 377 | } |
| 494 | 378 | } else { |
| 495 | - validateField( confirmField ); | |
| 379 | + validateField( 'conf_' + strippedFieldID, confirmField ); | |
| 496 | 380 | } |
| 497 | 381 | } |
| 498 | 382 | |
| 499 | 383 | function checkNumberField( field, errors ) { |
| @@ -505,8 +389,9 @@ | ||
| 505 | 389 | if ( ! ( fieldID in errors ) ) { |
| 506 | 390 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 507 | 391 | } |
| 508 | 392 | } |
| 393 | + return errors; | |
| 509 | 394 | } |
| 510 | 395 | |
| 511 | 396 | function checkPatternField( field, errors ) { |
| 512 | 397 | var fieldID, |
| @@ -521,47 +406,11 @@ | ||
| 521 | 406 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 522 | 407 | } |
| 523 | 408 | } |
| 524 | 409 | } |
| 410 | + return errors; | |
| 525 | 411 | } |
| 526 | 412 | |
| 527 | - /** | |
| 528 | - * Set color for select placeholders. | |
| 529 | - * | |
| 530 | - * @since 6.5.1 | |
| 531 | - */ | |
| 532 | - function setSelectPlaceholderColor() { | |
| 533 | - var selects = document.querySelectorAll( '.form-field select' ), | |
| 534 | - styleElement = document.querySelector( '.with_frm_style' ), | |
| 535 | - textColorDisabled = styleElement ? getComputedStyle( styleElement ).getPropertyValue( '--text-color-disabled' ).trim() : '', | |
| 536 | - changeSelectColor; | |
| 537 | - | |
| 538 | - // Exit if there are no select elements or the textColorDisabled property is missing | |
| 539 | - if ( ! selects.length || ! textColorDisabled ) { | |
| 540 | - return; | |
| 541 | - } | |
| 542 | - | |
| 543 | - // Function to change the color of a select element | |
| 544 | - changeSelectColor = function( select ) { | |
| 545 | - if ( hasClass( select.options[select.selectedIndex], 'frm-select-placeholder' ) ) { | |
| 546 | - select.style.setProperty( 'color', textColorDisabled, 'important' ); | |
| 547 | - } else { | |
| 548 | - select.style.color = ''; | |
| 549 | - } | |
| 550 | - }; | |
| 551 | - | |
| 552 | - // Use a loop to iterate through each select element | |
| 553 | - Array.prototype.forEach.call( selects, function( select ) { | |
| 554 | - // Apply the color change to each select element | |
| 555 | - changeSelectColor( select ); | |
| 556 | - | |
| 557 | - // Add an event listener for future changes | |
| 558 | - select.addEventListener( 'change', function() { | |
| 559 | - changeSelectColor( select ); | |
| 560 | - }); | |
| 561 | - }); | |
| 562 | - } | |
| 563 | - | |
| 564 | 413 | function hasInvisibleRecaptcha( object ) { |
| 565 | 414 | var recaptcha, recaptchaID, alreadyChecked; |
| 566 | 415 | |
| 567 | 416 | if ( isGoingToPrevPage( object ) ) { |
| @@ -646,9 +495,9 @@ | ||
| 646 | 495 | return validate; |
| 647 | 496 | } |
| 648 | 497 | |
| 649 | 498 | function getFormErrors( object, action ) { |
| 650 | - var fieldset, data, success, error, shouldTriggerEvent; | |
| 499 | + var fieldset; | |
| 651 | 500 | |
| 652 | 501 | if ( typeof action === 'undefined' ) { |
| 653 | 502 | jQuery( object ).find( 'input[name="frm_action"]' ).val(); |
| 654 | 503 | } |
| @@ -654,204 +503,145 @@ | ||
| 654 | 503 | } |
| 655 | 504 | |
| 656 | 505 | fieldset = jQuery( object ).find( '.frm_form_field' ); |
| 657 | 506 | fieldset.addClass( 'frm_doing_ajax' ); |
| 507 | + jQuery.ajax({ | |
| 508 | + type: 'POST', url: frm_js.ajax_url, | |
| 509 | + data: jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce, | |
| 510 | + success: function( response ) { | |
| 511 | + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay, | |
| 512 | + $fieldCont, key, inCollapsedSection, frmTrigger, | |
| 513 | + defaultResponse = { 'content': '', 'errors': {}, 'pass': false }; | |
| 514 | + if ( response === null ) { | |
| 515 | + response = defaultResponse; | |
| 516 | + } | |
| 658 | 517 | |
| 659 | - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase | |
| 660 | - shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' ); | |
| 661 | - | |
| 662 | - success = function( response ) { | |
| 663 | - var defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay, | |
| 664 | - $fieldCont, key, inCollapsedSection, frmTrigger, newTab; | |
| 665 | - | |
| 666 | - defaultResponse = { | |
| 667 | - content: '', | |
| 668 | - errors: {}, | |
| 669 | - pass: false | |
| 670 | - }; | |
| 671 | - | |
| 672 | - if ( response === null ) { | |
| 673 | - response = defaultResponse; | |
| 674 | - } | |
| 675 | - | |
| 676 | - response = response.replace( /^\s+|\s+$/g, '' ); | |
| 677 | - if ( response.indexOf( '{' ) === 0 ) { | |
| 678 | - response = JSON.parse( response ); | |
| 679 | - } else { | |
| 680 | - response = defaultResponse; | |
| 681 | - } | |
| 682 | - | |
| 683 | - if ( typeof response.redirect !== 'undefined' ) { | |
| 684 | - if ( shouldTriggerEvent ) { | |
| 685 | - triggerCustomEvent( object, 'frmSubmitEvent' ); | |
| 686 | - return; | |
| 518 | + response = response.replace( /^\s+|\s+$/g, '' ); | |
| 519 | + if ( response.indexOf( '{' ) === 0 ) { | |
| 520 | + response = JSON.parse( response ); | |
| 521 | + } else { | |
| 522 | + response = defaultResponse; | |
| 687 | 523 | } |
| 688 | 524 | |
| 689 | - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]); | |
| 690 | - | |
| 691 | - if ( ! response.openInNewTab ) { | |
| 692 | - // We return here because we're redirecting there is no need to update content. | |
| 525 | + if ( typeof response.redirect !== 'undefined' ) { | |
| 526 | + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]); | |
| 693 | 527 | window.location = response.redirect; |
| 694 | - return; | |
| 695 | - } | |
| 528 | + } else if ( response.content !== '' ) { | |
| 529 | + // the form or success message was returned | |
| 696 | 530 | |
| 697 | - // We don't return here because we're opening in a new tab, the old tab will still update. | |
| 698 | - newTab = window.open( response.redirect, '_blank' ); | |
| 699 | - if ( ! newTab && response.fallbackMsg && response.content ) { | |
| 700 | - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' ); | |
| 701 | - } | |
| 702 | - } | |
| 531 | + removeSubmitLoading( jQuery( object ) ); | |
| 532 | + if ( frm_js.offset != -1 ) { | |
| 533 | + frmFrontForm.scrollMsg( jQuery( object ), false ); | |
| 534 | + } | |
| 535 | + formID = jQuery( object ).find( 'input[name="form_id"]' ).val(); | |
| 536 | + response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' ); | |
| 537 | + replaceContent = jQuery( object ).closest( '.frm_forms' ); | |
| 538 | + removeAddedScripts( replaceContent, formID ); | |
| 539 | + delay = maybeSlideOut( replaceContent, response.content ); | |
| 703 | 540 | |
| 704 | - if ( response.content !== '' ) { | |
| 705 | - // the form or success message was returned | |
| 541 | + setTimeout( | |
| 542 | + function() { | |
| 543 | + var container, input, previousInput; | |
| 706 | 544 | |
| 707 | - if ( shouldTriggerEvent ) { | |
| 708 | - triggerCustomEvent( object, 'frmSubmitEvent' ); | |
| 709 | - return; | |
| 710 | - } | |
| 545 | + replaceContent.replaceWith( response.content ); | |
| 711 | 546 | |
| 712 | - removeSubmitLoading( jQuery( object ) ); | |
| 713 | - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase | |
| 714 | - frmFrontForm.scrollMsg( jQuery( object ), false ); | |
| 715 | - } | |
| 547 | + addUrlParam( response ); | |
| 716 | 548 | |
| 717 | - formID = jQuery( object ).find( 'input[name="form_id"]' ).val(); | |
| 718 | - response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' ); | |
| 719 | - replaceContent = jQuery( object ).closest( '.frm_forms' ); | |
| 720 | - removeAddedScripts( replaceContent, formID ); | |
| 721 | - delay = maybeSlideOut( replaceContent, response.content ); | |
| 549 | + if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase | |
| 550 | + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val(); | |
| 551 | + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val(); | |
| 552 | + frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object ); | |
| 553 | + } | |
| 722 | 554 | |
| 723 | - setTimeout( | |
| 724 | - function() { | |
| 725 | - var container, input, previousInput; | |
| 555 | + if ( typeof response.recaptcha !== 'undefined' ) { | |
| 556 | + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' ); | |
| 557 | + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">'; | |
| 558 | + previousInput = container.find( 'input[name="recaptcha_checked"]' ); | |
| 726 | 559 | |
| 727 | - replaceContent.replaceWith( response.content ); | |
| 560 | + if ( previousInput.length ) { | |
| 561 | + previousInput.replaceWith( input ); | |
| 562 | + } else { | |
| 563 | + container.append( input ); | |
| 564 | + } | |
| 565 | + } | |
| 728 | 566 | |
| 729 | - addUrlParam( response ); | |
| 567 | + afterFormSubmitted( object, response ); | |
| 568 | + }, | |
| 569 | + delay | |
| 570 | + ); | |
| 571 | + } else if ( Object.keys( response.errors ).length ) { | |
| 572 | + // errors were returned | |
| 730 | 573 | |
| 731 | - if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase | |
| 732 | - pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val(); | |
| 733 | - formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val(); | |
| 734 | - frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object ); | |
| 735 | - } | |
| 574 | + removeSubmitLoading( jQuery( object ), 'enable' ); | |
| 736 | 575 | |
| 737 | - if ( typeof response.recaptcha !== 'undefined' ) { | |
| 738 | - container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' ); | |
| 739 | - input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">'; | |
| 740 | - previousInput = container.find( 'input[name="recaptcha_checked"]' ); | |
| 576 | + //show errors | |
| 577 | + contSubmit = true; | |
| 578 | + removeAllErrors(); | |
| 741 | 579 | |
| 742 | - if ( previousInput.length ) { | |
| 743 | - previousInput.replaceWith( input ); | |
| 744 | - } else { | |
| 745 | - container.append( input ); | |
| 746 | - } | |
| 747 | - } | |
| 580 | + $fieldCont = null; | |
| 748 | 581 | |
| 749 | - afterFormSubmitted( object, response ); | |
| 750 | - }, | |
| 751 | - delay | |
| 752 | - ); | |
| 753 | - } else if ( Object.keys( response.errors ).length ) { | |
| 754 | - // errors were returned | |
| 755 | - removeSubmitLoading( jQuery( object ), 'enable' ); | |
| 582 | + for ( key in response.errors ) { | |
| 583 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 756 | 584 | |
| 757 | - //show errors | |
| 758 | - contSubmit = true; | |
| 759 | - removeAllErrors(); | |
| 760 | - | |
| 761 | - $fieldCont = null; | |
| 762 | - | |
| 763 | - for ( key in response.errors ) { | |
| 764 | - $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 765 | - | |
| 766 | - if ( $fieldCont.length ) { | |
| 767 | - if ( ! $fieldCont.is( ':visible' ) ) { | |
| 768 | - inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); | |
| 769 | - if ( inCollapsedSection.length ) { | |
| 770 | - frmTrigger = inCollapsedSection.prev(); | |
| 771 | - if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { | |
| 772 | - // If the frmTrigger object is the section description, check to see if the previous element is the trigger | |
| 773 | - frmTrigger = frmTrigger.prev( '.frm_trigger' ); | |
| 585 | + if ( $fieldCont.length ) { | |
| 586 | + if ( ! $fieldCont.is( ':visible' ) ) { | |
| 587 | + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); | |
| 588 | + if ( inCollapsedSection.length ) { | |
| 589 | + frmTrigger = inCollapsedSection.prev(); | |
| 590 | + if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { | |
| 591 | + // If the frmTrigger object is the section description, check to see if the previous element is the trigger | |
| 592 | + frmTrigger = frmTrigger.prev( '.frm_trigger' ); | |
| 593 | + } | |
| 594 | + frmTrigger.trigger( 'click' ); | |
| 774 | 595 | } |
| 775 | - frmTrigger.trigger( 'click' ); | |
| 776 | 596 | } |
| 777 | - } | |
| 778 | 597 | |
| 779 | - if ( $fieldCont.is( ':visible' ) ) { | |
| 780 | - addFieldError( $fieldCont, key, response.errors ); | |
| 781 | - contSubmit = false; | |
| 598 | + if ( $fieldCont.is( ':visible' ) ) { | |
| 599 | + addFieldError( $fieldCont, key, response.errors ); | |
| 600 | + contSubmit = false; | |
| 601 | + } | |
| 782 | 602 | } |
| 783 | 603 | } |
| 784 | - } | |
| 785 | 604 | |
| 786 | - jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() { | |
| 787 | - var $recaptcha = jQuery( this ), | |
| 788 | - recaptchaID = $recaptcha.data( 'rid' ); | |
| 605 | + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() { | |
| 606 | + var $recaptcha = jQuery( this ), | |
| 607 | + recaptchaID = $recaptcha.data( 'rid' ); | |
| 789 | 608 | |
| 790 | - if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { | |
| 791 | - if ( recaptchaID ) { | |
| 792 | - grecaptcha.reset( recaptchaID ); | |
| 793 | - } else { | |
| 794 | - grecaptcha.reset(); | |
| 609 | + if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { | |
| 610 | + if ( recaptchaID ) { | |
| 611 | + grecaptcha.reset( recaptchaID ); | |
| 612 | + } else { | |
| 613 | + grecaptcha.reset(); | |
| 614 | + } | |
| 795 | 615 | } |
| 796 | - } | |
| 797 | - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) { | |
| 798 | - hcaptcha.reset(); | |
| 799 | - } | |
| 800 | - }); | |
| 616 | + }); | |
| 801 | 617 | |
| 802 | - jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 618 | + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 803 | 619 | |
| 804 | - fieldset.removeClass( 'frm_doing_ajax' ); | |
| 805 | - scrollToFirstField( object ); | |
| 620 | + fieldset.removeClass( 'frm_doing_ajax' ); | |
| 621 | + scrollToFirstField( object ); | |
| 806 | 622 | |
| 807 | - if ( contSubmit ) { | |
| 808 | - object.submit(); | |
| 623 | + if ( contSubmit ) { | |
| 624 | + object.submit(); | |
| 625 | + } else { | |
| 626 | + jQuery( object ).prepend( response.error_message ); | |
| 627 | + checkForErrorsAndMaybeSetFocus(); | |
| 628 | + } | |
| 809 | 629 | } else { |
| 810 | - jQuery( object ).prepend( response.error_message ); | |
| 811 | - checkForErrorsAndMaybeSetFocus(); | |
| 812 | - } | |
| 813 | - } else { | |
| 814 | - // there may have been a plugin conflict, or the form is not set to submit with ajax | |
| 630 | + // there may have been a plugin conflict, or the form is not set to submit with ajax | |
| 815 | 631 | |
| 816 | - showFileLoading( object ); | |
| 632 | + showFileLoading( object ); | |
| 817 | 633 | |
| 634 | + object.submit(); | |
| 635 | + } | |
| 636 | + }, | |
| 637 | + error: function() { | |
| 638 | + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false ); | |
| 818 | 639 | object.submit(); |
| 819 | 640 | } |
| 820 | - }; | |
| 821 | - | |
| 822 | - error = function() { | |
| 823 | - jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false ); | |
| 824 | - object.submit(); | |
| 825 | - }; | |
| 826 | - | |
| 827 | - postToAjaxUrl( object, data, success, error ); | |
| 641 | + }); | |
| 828 | 642 | } |
| 829 | 643 | |
| 830 | - function postToAjaxUrl( form, data, success, error ) { | |
| 831 | - var ajaxUrl, action, ajaxParams; | |
| 832 | - | |
| 833 | - ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase | |
| 834 | - action = form.getAttribute( 'action' ); | |
| 835 | - | |
| 836 | - if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) { | |
| 837 | - ajaxUrl = action.split( '?action=frm_forms_preview' )[0]; | |
| 838 | - } | |
| 839 | - | |
| 840 | - ajaxParams = { | |
| 841 | - type: 'POST', | |
| 842 | - url: ajaxUrl, | |
| 843 | - data: data, | |
| 844 | - success: success | |
| 845 | - }; | |
| 846 | - | |
| 847 | - if ( 'function' === typeof error ) { | |
| 848 | - ajaxParams.error = error; | |
| 849 | - } | |
| 850 | - | |
| 851 | - jQuery.ajax( ajaxParams ); | |
| 852 | - } | |
| 853 | - | |
| 854 | 644 | function afterFormSubmitted( object, response ) { |
| 855 | 645 | var formCompleted = jQuery( response.content ).find( '.frm_message' ); |
| 856 | 646 | if ( formCompleted.length ) { |
| 857 | 647 | jQuery( document ).trigger( 'frmFormComplete', [ object, response ]); |
| @@ -917,9 +707,9 @@ | ||
| 917 | 707 | return kvp.join( '&' ); |
| 918 | 708 | } |
| 919 | 709 | |
| 920 | 710 | function addFieldError( $fieldCont, key, jsErrors ) { |
| 921 | - var input, id, describedBy, roleString; | |
| 711 | + var input, id, describedBy; | |
| 922 | 712 | if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) { |
| 923 | 713 | $fieldCont.addClass( 'frm_blank_field' ); |
| 924 | 714 | input = $fieldCont.find( 'input, select, textarea' ); |
| 925 | 715 | id = 'frm_error_field_' + key; |
| @@ -932,22 +722,16 @@ | ||
| 932 | 722 | $fieldCont.append( |
| 933 | 723 | jsErrors[key] |
| 934 | 724 | ); |
| 935 | 725 | } else { |
| 936 | - roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase | |
| 937 | - $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' ); | |
| 726 | + $fieldCont.append( '<div class="frm_error" id="' + id + '">' + jsErrors[key] + '</div>' ); | |
| 938 | 727 | } |
| 939 | 728 | |
| 940 | 729 | if ( typeof describedBy === 'undefined' ) { |
| 941 | 730 | describedBy = id; |
| 942 | - } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) { | |
| 943 | - if ( input.data( 'error-first' ) === 0 ) { | |
| 944 | - describedBy = describedBy + ' ' + id; | |
| 945 | - } else { | |
| 946 | - describedBy = id + ' ' + describedBy; | |
| 947 | - } | |
| 731 | + } else if ( describedBy.indexOf( id ) === -1 ) { | |
| 732 | + describedBy = describedBy + ' ' + id; | |
| 948 | 733 | } |
| 949 | - | |
| 950 | 734 | input.attr( 'aria-describedby', describedBy ); |
| 951 | 735 | } |
| 952 | 736 | input.attr( 'aria-invalid', true ); |
| 953 | 737 | |
| @@ -963,9 +747,8 @@ | ||
| 963 | 747 | |
| 964 | 748 | $fieldCont.removeClass( 'frm_blank_field has-error' ); |
| 965 | 749 | errorMessage.remove(); |
| 966 | 750 | input.attr( 'aria-invalid', false ); |
| 967 | - input.removeAttr( 'aria-describedby' ); | |
| 968 | 751 | |
| 969 | 752 | if ( typeof describedBy !== 'undefined' ) { |
| 970 | 753 | describedBy = describedBy.replace( errorId, '' ); |
| 971 | 754 | input.attr( 'aria-describedby', describedBy ); |
| @@ -1080,14 +863,14 @@ | ||
| 1080 | 863 | label.append( '<span class="frm-wait"></span>' ); |
| 1081 | 864 | |
| 1082 | 865 | jQuery.ajax({ |
| 1083 | 866 | type: 'POST', |
| 1084 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 867 | + url: frm_js.ajax_url, | |
| 1085 | 868 | data: { |
| 1086 | 869 | action: 'frm_entries_send_email', |
| 1087 | 870 | entry_id: entryId, |
| 1088 | 871 | form_id: formId, |
| 1089 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 872 | + nonce: frm_js.nonce | |
| 1090 | 873 | }, |
| 1091 | 874 | success: function( msg ) { |
| 1092 | 875 | var admin = document.getElementById( 'wpbody' ); |
| 1093 | 876 | if ( admin === null ) { |
| @@ -1125,9 +908,32 @@ | ||
| 1125 | 908 | /********************************************** |
| 1126 | 909 | * Fallback functions |
| 1127 | 910 | *********************************************/ |
| 1128 | 911 | |
| 1129 | - function addTrimFallbackForIE() { | |
| 912 | + function addIndexOfFallbackForIE8() { | |
| 913 | + var len, from; | |
| 914 | + | |
| 915 | + if ( ! Array.prototype.indexOf ) { | |
| 916 | + Array.prototype.indexOf = function( elt /*, from*/ ) { | |
| 917 | + len = this.length >>> 0; | |
| 918 | + | |
| 919 | + from = Number( arguments[1]) || 0; | |
| 920 | + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from ); | |
| 921 | + if ( from < 0 ) { | |
| 922 | + from += len; | |
| 923 | + } | |
| 924 | + | |
| 925 | + for ( ; from < len; from++ ) { | |
| 926 | + if ( from in this && this[from] === elt ) { | |
| 927 | + return from; | |
| 928 | + } | |
| 929 | + } | |
| 930 | + return -1; | |
| 931 | + }; | |
| 932 | + } | |
| 933 | + } | |
| 934 | + | |
| 935 | + function addTrimFallbackForIE8() { | |
| 1130 | 936 | if ( typeof String.prototype.trim !== 'function' ) { |
| 1131 | 937 | String.prototype.trim = function() { |
| 1132 | 938 | return this.replace( /^\s+|\s+$/g, '' ); |
| 1133 | 939 | }; |
| @@ -1133,9 +939,9 @@ | ||
| 1133 | 939 | }; |
| 1134 | 940 | } |
| 1135 | 941 | } |
| 1136 | 942 | |
| 1137 | - function addFilterFallbackForIE() { | |
| 943 | + function addFilterFallbackForIE8() { | |
| 1138 | 944 | var t, len, res, thisp, i, val; |
| 1139 | 945 | |
| 1140 | 946 | if ( ! Array.prototype.filter ) { |
| 1141 | 947 | |
| @@ -1166,8 +972,26 @@ | ||
| 1166 | 972 | }; |
| 1167 | 973 | } |
| 1168 | 974 | } |
| 1169 | 975 | |
| 976 | + function addKeysFallbackForIE8() { | |
| 977 | + var keys, i; | |
| 978 | + | |
| 979 | + if ( ! Object.keys ) { | |
| 980 | + Object.keys = function( obj ) { | |
| 981 | + keys = []; | |
| 982 | + | |
| 983 | + for ( i in obj ) { | |
| 984 | + if ( obj.hasOwnProperty( i ) ) { | |
| 985 | + keys.push( i ); | |
| 986 | + } | |
| 987 | + } | |
| 988 | + | |
| 989 | + return keys; | |
| 990 | + }; | |
| 991 | + } | |
| 992 | + } | |
| 993 | + | |
| 1170 | 994 | /** |
| 1171 | 995 | * Check for -webkit-box-shadow css value for input:-webkit-autofill selector. |
| 1172 | 996 | * If this is a match, the User is autofilling the input on a Webkit browser. |
| 1173 | 997 | * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete. |
| @@ -1178,37 +1002,8 @@ | ||
| 1178 | 1002 | this.parentNode.removeChild( this ); |
| 1179 | 1003 | } |
| 1180 | 1004 | } |
| 1181 | 1005 | |
| 1182 | - function maybeMakeHoneypotFieldsUntabbable() { | |
| 1183 | - document.addEventListener( 'keydown', handleKeyUp ); | |
| 1184 | - | |
| 1185 | - function handleKeyUp( event ) { | |
| 1186 | - var code; | |
| 1187 | - | |
| 1188 | - if ( 'undefined' !== typeof event.key ) { | |
| 1189 | - code = event.key; | |
| 1190 | - } else if ( 'undefined' !== typeof event.keyCode && 9 === event.keyCode ) { | |
| 1191 | - code = 'Tab'; | |
| 1192 | - } | |
| 1193 | - | |
| 1194 | - if ( 'Tab' === code ) { | |
| 1195 | - makeHoneypotFieldsUntabbable(); | |
| 1196 | - document.removeEventListener( 'keydown', handleKeyUp ); | |
| 1197 | - } | |
| 1198 | - } | |
| 1199 | - | |
| 1200 | - function makeHoneypotFieldsUntabbable() { | |
| 1201 | - document.querySelectorAll( '.frm_verify' ).forEach( | |
| 1202 | - function( input ) { | |
| 1203 | - if ( input.id && 0 === input.id.indexOf( 'frm_email_' ) ) { | |
| 1204 | - input.setAttribute( 'tabindex', -1 ); | |
| 1205 | - } | |
| 1206 | - } | |
| 1207 | - ); | |
| 1208 | - } | |
| 1209 | - } | |
| 1210 | - | |
| 1211 | 1006 | /** |
| 1212 | 1007 | * Focus on the first sub field when clicking to the primary label of combo field. |
| 1213 | 1008 | * |
| 1214 | 1009 | * @since 4.10.02 |
| @@ -1213,11 +1008,11 @@ | ||
| 1213 | 1008 | * |
| 1214 | 1009 | * @since 4.10.02 |
| 1215 | 1010 | */ |
| 1216 | 1011 | function changeFocusWhenClickComboFieldLabel() { |
| 1217 | - var label; | |
| 1012 | + let label; | |
| 1218 | 1013 | |
| 1219 | - var comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' ); | |
| 1014 | + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' ); | |
| 1220 | 1015 | comboInputsContainer.forEach( function( inputsContainer ) { |
| 1221 | 1016 | if ( ! inputsContainer.closest( '.frm_form_field' ) ) { |
| 1222 | 1017 | return; |
| 1223 | 1018 | } |
| @@ -1235,12 +1030,8 @@ | ||
| 1235 | 1030 | |
| 1236 | 1031 | function checkForErrorsAndMaybeSetFocus() { |
| 1237 | 1032 | var errors, element, timeoutCallback; |
| 1238 | 1033 | |
| 1239 | - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase | |
| 1240 | - return; | |
| 1241 | - } | |
| 1242 | - | |
| 1243 | 1034 | errors = document.querySelectorAll( '.frm_form_field .frm_error' ); |
| 1244 | 1035 | if ( ! errors.length ) { |
| 1245 | 1036 | return; |
| 1246 | 1037 | } |
| @@ -1274,246 +1065,10 @@ | ||
| 1274 | 1065 | } |
| 1275 | 1066 | } while ( element.previousSibling ); |
| 1276 | 1067 | } |
| 1277 | 1068 | |
| 1278 | - /** | |
| 1279 | - * Checks if is on IE browser. | |
| 1280 | - * | |
| 1281 | - * @since 5.4 | |
| 1282 | - * | |
| 1283 | - * @return {Boolean} | |
| 1284 | - */ | |
| 1285 | - function isIE() { | |
| 1286 | - return navigator.userAgent.indexOf( 'MSIE' ) > -1 || navigator.userAgent.indexOf( 'Trident' ) > -1; | |
| 1287 | - } | |
| 1288 | - | |
| 1289 | - /** | |
| 1290 | - * Does the same as jQuery( document ).on( 'event', 'selector', handler ). | |
| 1291 | - * | |
| 1292 | - * @since 5.4 | |
| 1293 | - * | |
| 1294 | - * @param {String} event Event name. | |
| 1295 | - * @param {String} selector Selector. | |
| 1296 | - * @param {Function} handler Handler. | |
| 1297 | - * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`. | |
| 1298 | - */ | |
| 1299 | - function documentOn( event, selector, handler, options ) { | |
| 1300 | - if ( 'undefined' === typeof options ) { | |
| 1301 | - options = false; | |
| 1302 | - } | |
| 1303 | - | |
| 1304 | - document.addEventListener( event, function( e ) { | |
| 1305 | - var target; | |
| 1306 | - | |
| 1307 | - // loop parent nodes from the target to the delegation node. | |
| 1308 | - for ( target = e.target; target && target != this; target = target.parentNode ) { | |
| 1309 | - if ( target && target.matches && target.matches( selector ) ) { | |
| 1310 | - handler.call( target, e ); | |
| 1311 | - break; | |
| 1312 | - } | |
| 1313 | - } | |
| 1314 | - }, options ); | |
| 1315 | - } | |
| 1316 | - | |
| 1317 | - function initFloatingLabels() { | |
| 1318 | - var checkFloatLabel, checkDropdownLabel, checkPlaceholderIE, runOnLoad, selector, floatClass; | |
| 1319 | - | |
| 1320 | - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea'; | |
| 1321 | - floatClass = 'frm_label_float_top'; | |
| 1322 | - | |
| 1323 | - checkFloatLabel = function( input ) { | |
| 1324 | - var container, shouldFloatTop, firstOpt; | |
| 1325 | - | |
| 1326 | - container = input.closest( '.frm_inside_container' ); | |
| 1327 | - if ( ! container ) { | |
| 1328 | - return; | |
| 1329 | - } | |
| 1330 | - | |
| 1331 | - shouldFloatTop = input.value || document.activeElement === input; | |
| 1332 | - | |
| 1333 | - container.classList.toggle( floatClass, shouldFloatTop ); | |
| 1334 | - | |
| 1335 | - if ( 'SELECT' === input.tagName ) { | |
| 1336 | - firstOpt = input.querySelector( 'option:first-child' ); | |
| 1337 | - | |
| 1338 | - if ( shouldFloatTop ) { | |
| 1339 | - if ( firstOpt.hasAttribute( 'data-label' ) ) { | |
| 1340 | - firstOpt.textContent = firstOpt.getAttribute( 'data-label' ); | |
| 1341 | - firstOpt.removeAttribute( 'data-label' ); | |
| 1342 | - } | |
| 1343 | - } else { | |
| 1344 | - if ( firstOpt.textContent ) { | |
| 1345 | - firstOpt.setAttribute( 'data-label', firstOpt.textContent ); | |
| 1346 | - firstOpt.textContent = ''; | |
| 1347 | - } | |
| 1348 | - } | |
| 1349 | - } else if ( isIE() ) { | |
| 1350 | - checkPlaceholderIE( input ); | |
| 1351 | - } | |
| 1352 | - }; | |
| 1353 | - | |
| 1354 | - checkDropdownLabel = function() { | |
| 1355 | - document.querySelectorAll( '.frm-show-form .frm_inside_container:not(.' + floatClass + ') select' ).forEach( function( input ) { | |
| 1356 | - var firstOpt = input.querySelector( 'option:first-child' ); | |
| 1357 | - | |
| 1358 | - if ( firstOpt.textContent ) { | |
| 1359 | - firstOpt.setAttribute( 'data-label', firstOpt.textContent ); | |
| 1360 | - firstOpt.textContent = ''; | |
| 1361 | - } | |
| 1362 | - }); | |
| 1363 | - }; | |
| 1364 | - | |
| 1365 | - checkPlaceholderIE = function( input ) { | |
| 1366 | - if ( input.value ) { | |
| 1367 | - // Don't need to handle this case because placeholder isn't shown. | |
| 1368 | - return; | |
| 1369 | - } | |
| 1370 | - | |
| 1371 | - if ( document.activeElement === input ) { | |
| 1372 | - if ( input.hasAttribute( 'data-placeholder' ) ) { | |
| 1373 | - input.placeholder = input.getAttribute( 'data-placeholder' ); | |
| 1374 | - input.removeAttribute( 'data-placeholder' ); | |
| 1375 | - } | |
| 1376 | - } else { | |
| 1377 | - if ( input.placeholder ) { | |
| 1378 | - input.setAttribute( 'data-placeholder', input.placeholder ); | |
| 1379 | - input.placeholder = ''; | |
| 1380 | - } | |
| 1381 | - } | |
| 1382 | - }; | |
| 1383 | - | |
| 1384 | - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) { | |
| 1385 | - documentOn( | |
| 1386 | - eventName, | |
| 1387 | - selector, | |
| 1388 | - function( event ) { | |
| 1389 | - checkFloatLabel( event.target ); | |
| 1390 | - }, | |
| 1391 | - true | |
| 1392 | - ); | |
| 1393 | - }); | |
| 1394 | - | |
| 1395 | - jQuery( document ).on( 'change', selector, function( event ) { | |
| 1396 | - checkFloatLabel( event.target ); | |
| 1397 | - }); | |
| 1398 | - | |
| 1399 | - runOnLoad = function( firstLoad ) { | |
| 1400 | - if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) { | |
| 1401 | - checkFloatLabel( document.activeElement ); | |
| 1402 | - } else if ( firstLoad ) { | |
| 1403 | - document.querySelectorAll( '.frm_inside_container' ).forEach( | |
| 1404 | - function( container ) { | |
| 1405 | - var input = container.querySelector( 'input, select, textarea' ); | |
| 1406 | - if ( input && '' !== input.value ) { | |
| 1407 | - checkFloatLabel( input ); | |
| 1408 | - } | |
| 1409 | - } | |
| 1410 | - ); | |
| 1411 | - } | |
| 1412 | - | |
| 1413 | - checkDropdownLabel(); | |
| 1414 | - | |
| 1415 | - if ( isIE() ) { | |
| 1416 | - document.querySelectorAll( selector ).forEach( function( input ) { | |
| 1417 | - checkPlaceholderIE( input ); | |
| 1418 | - }); | |
| 1419 | - } | |
| 1420 | - }; | |
| 1421 | - | |
| 1422 | - runOnLoad( true ); | |
| 1423 | - | |
| 1424 | - jQuery( document ).on( 'frmPageChanged', function( event ) { | |
| 1425 | - runOnLoad(); | |
| 1426 | - }); | |
| 1427 | - | |
| 1428 | - document.addEventListener( 'frm_after_start_over', function( event ) { | |
| 1429 | - runOnLoad(); | |
| 1430 | - }); | |
| 1431 | - } | |
| 1432 | - | |
| 1433 | - function shouldUpdateValidityMessage( target ) { | |
| 1434 | - if ( 'INPUT' !== target.nodeName ) { | |
| 1435 | - return false; | |
| 1436 | - } | |
| 1437 | - | |
| 1438 | - if ( ! target.dataset.invmsg ) { | |
| 1439 | - return false; | |
| 1440 | - } | |
| 1441 | - | |
| 1442 | - if ( 'text' !== target.getAttribute( 'type' ) ) { | |
| 1443 | - return false; | |
| 1444 | - } | |
| 1445 | - | |
| 1446 | - if ( target.classList.contains( 'frm_verify' ) ) { | |
| 1447 | - return false; | |
| 1448 | - } | |
| 1449 | - | |
| 1450 | - return true; | |
| 1451 | - } | |
| 1452 | - | |
| 1453 | - function maybeClearCustomValidityMessage( event, field ) { | |
| 1454 | - var key, | |
| 1455 | - isInvalid = false; | |
| 1456 | - | |
| 1457 | - if ( ! shouldUpdateValidityMessage( field ) ) { | |
| 1458 | - return; | |
| 1459 | - } | |
| 1460 | - | |
| 1461 | - for ( key in field.validity ) { | |
| 1462 | - if ( 'customError' === key ) { | |
| 1463 | - continue; | |
| 1464 | - } | |
| 1465 | - if ( 'valid' !== key && field.validity[ key ] === true ) { | |
| 1466 | - isInvalid = true; | |
| 1467 | - break; | |
| 1468 | - } | |
| 1469 | - }; | |
| 1470 | - | |
| 1471 | - if ( ! isInvalid ) { | |
| 1472 | - field.setCustomValidity( '' ); | |
| 1473 | - } | |
| 1474 | - } | |
| 1475 | - | |
| 1476 | - function maybeShowNewTabFallbackMessage() { | |
| 1477 | - var messageEl; | |
| 1478 | - | |
| 1479 | - if ( ! window.frmShowNewTabFallback ) { | |
| 1480 | - return; | |
| 1481 | - } | |
| 1482 | - | |
| 1483 | - messageEl = document.querySelector( '#frm_form_' + frmShowNewTabFallback.formId + '_container .frm_message' ); | |
| 1484 | - if ( ! messageEl ) { | |
| 1485 | - return; | |
| 1486 | - } | |
| 1487 | - | |
| 1488 | - messageEl.insertAdjacentHTML( 'beforeend', ' ' + frmShowNewTabFallback.message ); | |
| 1489 | - } | |
| 1490 | - | |
| 1491 | - function setCustomValidityMessage() { | |
| 1492 | - var forms, length, index; | |
| 1493 | - | |
| 1494 | - forms = document.getElementsByClassName( 'frm-show-form' ); | |
| 1495 | - length = forms.length; | |
| 1496 | - | |
| 1497 | - for ( index = 0; index < length; ++index ) { | |
| 1498 | - forms[ index ].addEventListener( | |
| 1499 | - 'invalid', | |
| 1500 | - function( event ) { | |
| 1501 | - var target = event.target; | |
| 1502 | - | |
| 1503 | - if ( shouldUpdateValidityMessage( target ) ) { | |
| 1504 | - target.setCustomValidity( target.dataset.invmsg ); | |
| 1505 | - } | |
| 1506 | - }, | |
| 1507 | - true | |
| 1508 | - ); | |
| 1509 | - } | |
| 1510 | - } | |
| 1511 | - | |
| 1512 | 1069 | return { |
| 1513 | 1070 | init: function() { |
| 1514 | - maybeAddPolyfills(); | |
| 1515 | - | |
| 1516 | 1071 | jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); |
| 1517 | 1072 | jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm ); |
| 1518 | 1073 | |
| 1519 | 1074 | jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() { |
| @@ -1528,11 +1083,11 @@ | ||
| 1528 | 1083 | |
| 1529 | 1084 | jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail ); |
| 1530 | 1085 | |
| 1531 | 1086 | 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 ); |
| 1087 | + 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 ); | |
| 1532 | 1088 | |
| 1533 | 1089 | jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange ); |
| 1534 | - maybeMakeHoneypotFieldsUntabbable(); | |
| 1535 | 1090 | |
| 1536 | 1091 | jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick ); |
| 1537 | 1092 | jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv ); |
| 1538 | 1093 | |
| @@ -1540,23 +1095,13 @@ | ||
| 1540 | 1095 | |
| 1541 | 1096 | // Focus on the first sub field when clicking to the primary label of combo field. |
| 1542 | 1097 | changeFocusWhenClickComboFieldLabel(); |
| 1543 | 1098 | |
| 1544 | - // Add fallbacks for IE. | |
| 1545 | - addTrimFallbackForIE(); // Trim only works in IE10+. | |
| 1546 | - addFilterFallbackForIE(); // Filter is not supported in any version of IE. | |
| 1547 | - | |
| 1548 | - initFloatingLabels(); | |
| 1549 | - maybeShowNewTabFallbackMessage(); | |
| 1550 | - | |
| 1551 | - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage ); | |
| 1552 | - setCustomValidityMessage(); | |
| 1553 | - jQuery( document ).on( 'frmFieldChanged', maybeClearCustomValidityMessage ); | |
| 1554 | - | |
| 1555 | - setSelectPlaceholderColor(); | |
| 1556 | - | |
| 1557 | - // Elementor popup show event. Fix Elementor Popup && FF Captcha field conflicts | |
| 1558 | - jQuery( document ).on( 'elementor/popup/show', frmRecaptcha ); | |
| 1099 | + // Add fallbacks for the beloved IE8 | |
| 1100 | + addIndexOfFallbackForIE8(); | |
| 1101 | + addTrimFallbackForIE8(); | |
| 1102 | + addFilterFallbackForIE8(); | |
| 1103 | + addKeysFallbackForIE8(); | |
| 1559 | 1104 | }, |
| 1560 | 1105 | |
| 1561 | 1106 | getFieldId: function( field, fullID ) { |
| 1562 | 1107 | return getFieldId( field, fullID ); |
| @@ -1739,12 +1284,12 @@ | ||
| 1739 | 1284 | removeSubmitLoading: function( $object, enable, processesRunning ) { |
| 1740 | 1285 | removeSubmitLoading( $object, enable, processesRunning ); |
| 1741 | 1286 | }, |
| 1742 | 1287 | |
| 1743 | - scrollToID: function( id ) { | |
| 1744 | - var object = jQuery( document.getElementById( id ) ); | |
| 1745 | - frmFrontForm.scrollMsg( object, false ); | |
| 1746 | - }, | |
| 1288 | + scrollToID: function( id ) { | |
| 1289 | + var object = jQuery( document.getElementById( id ) ); | |
| 1290 | + frmFrontForm.scrollMsg( object, false ); | |
| 1291 | + }, | |
| 1747 | 1292 | |
| 1748 | 1293 | scrollMsg: function( id, object, animate ) { |
| 1749 | 1294 | var newPos, m, b, screenTop, screenBottom, |
| 1750 | 1295 | scrollObj = ''; |
| @@ -1760,12 +1305,12 @@ | ||
| 1760 | 1305 | } |
| 1761 | 1306 | |
| 1762 | 1307 | jQuery( scrollObj ).trigger( 'focus' ); |
| 1763 | 1308 | newPos = scrollObj.offset().top; |
| 1764 | - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase | |
| 1309 | + if ( ! newPos || frm_js.offset === '-1' ) { | |
| 1765 | 1310 | return; |
| 1766 | 1311 | } |
| 1767 | - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase | |
| 1312 | + newPos = newPos - frm_js.offset; | |
| 1768 | 1313 | |
| 1769 | 1314 | m = jQuery( 'html' ).css( 'margin-top' ); |
| 1770 | 1315 | b = jQuery( 'body' ).css( 'margin-top' ); |
| 1771 | 1316 | if ( m || b ) { |
| @@ -1802,9 +1347,9 @@ | ||
| 1802 | 1347 | |
| 1803 | 1348 | jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]); |
| 1804 | 1349 | |
| 1805 | 1350 | if ( e.selfTriggered !== true ) { |
| 1806 | - maybeValidateChange( this ); | |
| 1351 | + maybeValidateChange( fieldId, this ); | |
| 1807 | 1352 | } |
| 1808 | 1353 | }, |
| 1809 | 1354 | |
| 1810 | 1355 | savingDraft: function( object ) { |
| @@ -1868,11 +1413,9 @@ | ||
| 1868 | 1413 | }, |
| 1869 | 1414 | |
| 1870 | 1415 | visible: function( classes ) { |
| 1871 | 1416 | jQuery( classes ).css( 'visibility', 'visible' ); |
| 1872 | - }, | |
| 1873 | - | |
| 1874 | - triggerCustomEvent: triggerCustomEvent | |
| 1417 | + } | |
| 1875 | 1418 | }; |
| 1876 | 1419 | } |
| 1877 | 1420 | frmFrontForm = frmFrontFormJS(); |
| 1878 | 1421 | |
| @@ -1895,15 +1438,15 @@ | ||
| 1895 | 1438 | function frmUpdateField( entryId, fieldId, value, message, num ) { |
| 1896 | 1439 | jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' ); |
| 1897 | 1440 | jQuery.ajax({ |
| 1898 | 1441 | type: 'POST', |
| 1899 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1442 | + url: frm_js.ajax_url, | |
| 1900 | 1443 | data: { |
| 1901 | 1444 | action: 'frm_entries_update_field_ajax', |
| 1902 | 1445 | entry_id: entryId, |
| 1903 | 1446 | field_id: fieldId, |
| 1904 | 1447 | value: value, |
| 1905 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1448 | + nonce: frm_js.nonce | |
| 1906 | 1449 | }, |
| 1907 | 1450 | success: function() { |
| 1908 | 1451 | if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) { |
| 1909 | 1452 | jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' ); |
| @@ -1918,13 +1461,13 @@ | ||
| 1918 | 1461 | console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' ); |
| 1919 | 1462 | jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' ); |
| 1920 | 1463 | jQuery.ajax({ |
| 1921 | 1464 | type: 'POST', |
| 1922 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1465 | + url: frm_js.ajax_url, | |
| 1923 | 1466 | data: { |
| 1924 | 1467 | action: 'frm_entries_destroy', |
| 1925 | 1468 | entry: entryId, |
| 1926 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1469 | + nonce: frm_js.nonce | |
| 1927 | 1470 | }, |
| 1928 | 1471 | success: function( html ) { |
| 1929 | 1472 | if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) { |
| 1930 | 1473 | jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' ); |
| @@ -1945,14 +1488,14 @@ | ||
| 1945 | 1488 | console.warn( 'DEPRECATED: function frm_resend_email in v2.0' ); |
| 1946 | 1489 | $link.append( '<span class="spinner" style="display:inline"></span>' ); |
| 1947 | 1490 | jQuery.ajax({ |
| 1948 | 1491 | type: 'POST', |
| 1949 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1492 | + url: frm_js.ajax_url, | |
| 1950 | 1493 | data: { |
| 1951 | 1494 | action: 'frm_entries_send_email', |
| 1952 | 1495 | entry_id: entryId, |
| 1953 | 1496 | form_id: formId, |
| 1954 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1497 | + nonce: frm_js.nonce | |
| 1955 | 1498 | }, |
| 1956 | 1499 | success: function( msg ) { |
| 1957 | 1500 | $link.replaceWith( msg ); |
| 1958 | 1501 | } |