PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.08
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | js/formidable.js +228 -579 6.3.15.0.08 View file →
@@ -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
@@ -210,12 +159,8 @@
210 159 '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea'
211 160 ).filter( ':not(.frm_optional)' );
212 161 if ( requiredFields.length ) {
213 162 for ( r = 0, rl = requiredFields.length; r < rl; r++ ) {
214 - if ( hasClass( requiredFields[r], 'ed_button' ) ) {
215 - // skip rich text field buttons.
216 - continue;
217 - }
218 163 errors = checkRequiredField( requiredFields[r], errors );
219 164 }
220 165 }
221 166
@@ -222,10 +167,23 @@
222 167 fields = jQuery( object ).find( 'input,select,textarea' );
223 168 if ( fields.length ) {
224 169 for ( n = 0, nl = fields.length; n < nl; n++ ) {
225 170 field = fields[n];
226 - if ( '' !== field.value ) {
227 - validateFieldValue( 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 );
185 + }
228 186 }
229 187 }
230 188 }
231 189
@@ -233,26 +191,14 @@
233 191
234 192 return errors;
235 193 }
236 194
237 - /**
238 - * @since 5.0.10
239 - *
240 - * @param {object} element
241 - * @param {string} targetClass
242 - * @returns {boolean}
243 - */
244 - function hasClass( element, targetClass ) {
245 - var className = ' ' + element.className + ' ';
246 - return -1 !== className.indexOf( ' ' + targetClass + ' ' );
247 - }
248 -
249 - function maybeValidateChange( field ) {
195 + function maybeValidateChange( fieldId, field ) {
250 196 if ( field.type === 'url' ) {
251 197 maybeAddHttpToUrl( field );
252 198 }
253 199 if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) {
254 - validateField( field );
200 + validateField( fieldId, field );
255 201 }
256 202 }
257 203
258 204 function maybeAddHttpToUrl( field ) {
@@ -262,19 +208,29 @@
262 208 field.value = 'http://' + url;
263 209 }
264 210 }
265 211
266 - function validateField( field ) {
212 + function validateField( fieldId, field ) {
267 213 var key,
268 - errors = [],
269 - $fieldCont = jQuery( field ).closest( '.frm_form_field' );
214 + errors = [];
270 215
216 + var $fieldCont = jQuery( field ).closest( '.frm_form_field' );
271 217 if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) {
272 218 errors = checkRequiredField( field, errors );
273 219 }
274 220
275 221 if ( errors.length < 1 ) {
276 - 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 + }
277 233 }
278 234
279 235 removeFieldError( $fieldCont );
280 236 if ( Object.keys( errors ).length > 0 ) {
@@ -283,36 +239,15 @@
283 239 }
284 240 }
285 241 }
286 242
287 - function validateFieldValue( field, errors ) {
288 - if ( field.type === 'hidden' ) {
289 - // don't validate
290 - } else if ( field.type === 'number' ) {
291 - checkNumberField( field, errors );
292 - } else if ( field.type === 'email' ) {
293 - checkEmailField( field, errors );
294 - } else if ( field.type === 'password' ) {
295 - checkPasswordField( field, errors );
296 - } else if ( field.type === 'url' ) {
297 - checkUrlField( field, errors );
298 - } else if ( field.pattern !== null ) {
299 - checkPatternField( field, errors );
300 - }
301 -
302 - triggerCustomEvent( document, 'frm_validate_field_value', {
303 - field: field,
304 - errors: errors
305 - });
306 - }
307 -
308 243 function checkRequiredField( field, errors ) {
309 - var checkGroup, tempVal, i, placeholder,
244 + var checkGroup, fieldClasses, tempVal, i, placeholder,
310 245 val = '',
311 246 fieldID = '',
312 247 fileID = field.getAttribute( 'data-frmfile' );
313 248
314 - if ( field.type === 'hidden' && fileID === null && ! isAppointmentField( field ) && ! isInlineDatepickerField( field ) ) {
249 + if ( field.type === 'hidden' && fileID === null ) {
315 250 return errors;
316 251 }
317 252
318 253 if ( field.type === 'checkbox' || field.type === 'radio' ) {
@@ -330,9 +265,10 @@
330 265 val = getFileVals( fileID );
331 266 }
332 267 fieldID = fileID;
333 268 } else {
334 - if ( hasClass( field, 'frm_pos_none' ) ) {
269 + fieldClasses = field.className;
270 + if ( fieldClasses.indexOf( 'frm_pos_none' ) !== -1 ) {
335 271 // skip hidden other fields
336 272 return errors;
337 273 }
338 274
@@ -348,26 +284,17 @@
348 284 }
349 285 }
350 286 }
351 287
352 - if ( hasClass( field, 'frm_other_input' ) ) {
288 + if ( fieldClasses.indexOf( 'frm_other_input' ) === -1 ) {
289 + fieldID = getFieldId( field, true );
290 + } else {
353 291 fieldID = getFieldId( field, false );
354 -
355 - if ( val === '' ) {
356 - field = document.getElementById( field.id.replace( '-otext', '' ) );
357 - }
358 - } else {
359 - fieldID = getFieldId( field, true );
360 292 }
361 293
362 - if ( hasClass( field, 'frm_time_select' ) ) {
294 + if ( fieldClasses.indexOf( 'frm_time_select' ) !== -1 ) {
363 295 // set id for time field
364 296 fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' );
365 - } else if ( isSignatureField( field ) ) {
366 - if ( val === '' ) {
367 - val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val();
368 - }
369 - fieldID = fieldID.replace( '-typed', '' );
370 297 }
371 298
372 299 placeholder = field.getAttribute( 'data-frmplaceholder' );
373 300 if ( placeholder !== null && val === placeholder ) {
@@ -386,21 +313,8 @@
386 313
387 314 return errors;
388 315 }
389 316
390 - function isSignatureField( field ) {
391 - var name = field.getAttribute( 'name' );
392 - return 'string' === typeof name && '[typed]' === name.substr( -7 );
393 - }
394 -
395 - function isAppointmentField( field ) {
396 - return hasClass( field, 'ssa_appointment_form_field_appointment_id' );
397 - }
398 -
399 - function isInlineDatepickerField( field ) {
400 - return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' );
401 - }
402 -
403 317 function getFileVals( fileID ) {
404 318 var val = '',
405 319 fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' );
406 320
@@ -421,8 +335,9 @@
421 335 if ( ! ( fieldID in errors ) ) {
422 336 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
423 337 }
424 338 }
339 + return errors;
425 340 }
426 341
427 342 function checkEmailField( field, errors ) {
428 343 var fieldID = getFieldId( field, true ),
@@ -433,12 +348,14 @@
433 348 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
434 349 }
435 350
436 351 confirmField( field, errors );
352 + return errors;
437 353 }
438 354
439 355 function checkPasswordField( field, errors ) {
440 356 confirmField( field, errors );
357 + return errors;
441 358 }
442 359
443 360 function confirmField( field, errors ) {
444 361 var value, confirmValue, firstField,
@@ -458,9 +375,9 @@
458 375 if ( '' !== value && '' !== confirmValue && value !== confirmValue ) {
459 376 errors[ 'conf_' + strippedFieldID ] = getFieldValidationMessage( confirmField, 'data-confmsg' );
460 377 }
461 378 } else {
462 - validateField( confirmField );
379 + validateField( 'conf_' + strippedFieldID, confirmField );
463 380 }
464 381 }
465 382
466 383 function checkNumberField( field, errors ) {
@@ -472,8 +389,9 @@
472 389 if ( ! ( fieldID in errors ) ) {
473 390 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
474 391 }
475 392 }
393 + return errors;
476 394 }
477 395
478 396 function checkPatternField( field, errors ) {
479 397 var fieldID,
@@ -488,8 +406,9 @@
488 406 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
489 407 }
490 408 }
491 409 }
410 + return errors;
492 411 }
493 412
494 413 function hasInvisibleRecaptcha( object ) {
495 414 var recaptcha, recaptchaID, alreadyChecked;
@@ -576,9 +495,9 @@
576 495 return validate;
577 496 }
578 497
579 498 function getFormErrors( object, action ) {
580 - var fieldset, data, success, error, shouldTriggerEvent;
499 + var fieldset;
581 500
582 501 if ( typeof action === 'undefined' ) {
583 502 jQuery( object ).find( 'input[name="frm_action"]' ).val();
584 503 }
@@ -584,204 +503,145 @@
584 503 }
585 504
586 505 fieldset = jQuery( object ).find( '.frm_form_field' );
587 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 + }
588 517
589 - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase
590 - shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );
591 -
592 - success = function( response ) {
593 - var defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
594 - $fieldCont, key, inCollapsedSection, frmTrigger, newTab;
595 -
596 - defaultResponse = {
597 - content: '',
598 - errors: {},
599 - pass: false
600 - };
601 -
602 - if ( response === null ) {
603 - response = defaultResponse;
604 - }
605 -
606 - response = response.replace( /^\s+|\s+$/g, '' );
607 - if ( response.indexOf( '{' ) === 0 ) {
608 - response = JSON.parse( response );
609 - } else {
610 - response = defaultResponse;
611 - }
612 -
613 - if ( typeof response.redirect !== 'undefined' ) {
614 - if ( shouldTriggerEvent ) {
615 - triggerCustomEvent( object, 'frmSubmitEvent' );
616 - return;
518 + response = response.replace( /^\s+|\s+$/g, '' );
519 + if ( response.indexOf( '{' ) === 0 ) {
520 + response = JSON.parse( response );
521 + } else {
522 + response = defaultResponse;
617 523 }
618 524
619 - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
620 -
621 - if ( ! response.openInNewTab ) {
622 - // 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 ]);
623 527 window.location = response.redirect;
624 - return;
625 - }
528 + } else if ( response.content !== '' ) {
529 + // the form or success message was returned
626 530
627 - // We don't return here because we're opening in a new tab, the old tab will still update.
628 - newTab = window.open( response.redirect, '_blank' );
629 - if ( ! newTab && response.fallbackMsg && response.content ) {
630 - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' );
631 - }
632 - }
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 );
633 540
634 - if ( response.content !== '' ) {
635 - // the form or success message was returned
541 + setTimeout(
542 + function() {
543 + var container, input, previousInput;
636 544
637 - if ( shouldTriggerEvent ) {
638 - triggerCustomEvent( object, 'frmSubmitEvent' );
639 - return;
640 - }
545 + replaceContent.replaceWith( response.content );
641 546
642 - removeSubmitLoading( jQuery( object ) );
643 - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase
644 - frmFrontForm.scrollMsg( jQuery( object ), false );
645 - }
547 + addUrlParam( response );
646 548
647 - formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
648 - response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
649 - replaceContent = jQuery( object ).closest( '.frm_forms' );
650 - removeAddedScripts( replaceContent, formID );
651 - 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 + }
652 554
653 - setTimeout(
654 - function() {
655 - 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"]' );
656 559
657 - replaceContent.replaceWith( response.content );
560 + if ( previousInput.length ) {
561 + previousInput.replaceWith( input );
562 + } else {
563 + container.append( input );
564 + }
565 + }
658 566
659 - addUrlParam( response );
567 + afterFormSubmitted( object, response );
568 + },
569 + delay
570 + );
571 + } else if ( Object.keys( response.errors ).length ) {
572 + // errors were returned
660 573
661 - if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
662 - pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
663 - formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
664 - frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
665 - }
574 + removeSubmitLoading( jQuery( object ), 'enable' );
666 575
667 - if ( typeof response.recaptcha !== 'undefined' ) {
668 - container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' );
669 - input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">';
670 - previousInput = container.find( 'input[name="recaptcha_checked"]' );
576 + //show errors
577 + contSubmit = true;
578 + removeAllErrors();
671 579
672 - if ( previousInput.length ) {
673 - previousInput.replaceWith( input );
674 - } else {
675 - container.append( input );
676 - }
677 - }
580 + $fieldCont = null;
678 581
679 - afterFormSubmitted( object, response );
680 - },
681 - delay
682 - );
683 - } else if ( Object.keys( response.errors ).length ) {
684 - // errors were returned
685 - removeSubmitLoading( jQuery( object ), 'enable' );
582 + for ( key in response.errors ) {
583 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
686 584
687 - //show errors
688 - contSubmit = true;
689 - removeAllErrors();
690 -
691 - $fieldCont = null;
692 -
693 - for ( key in response.errors ) {
694 - $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
695 -
696 - if ( $fieldCont.length ) {
697 - if ( ! $fieldCont.is( ':visible' ) ) {
698 - inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
699 - if ( inCollapsedSection.length ) {
700 - frmTrigger = inCollapsedSection.prev();
701 - if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
702 - // If the frmTrigger object is the section description, check to see if the previous element is the trigger
703 - 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' );
704 595 }
705 - frmTrigger.trigger( 'click' );
706 596 }
707 - }
708 597
709 - if ( $fieldCont.is( ':visible' ) ) {
710 - addFieldError( $fieldCont, key, response.errors );
711 - contSubmit = false;
598 + if ( $fieldCont.is( ':visible' ) ) {
599 + addFieldError( $fieldCont, key, response.errors );
600 + contSubmit = false;
601 + }
712 602 }
713 603 }
714 - }
715 604
716 - jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() {
717 - var $recaptcha = jQuery( this ),
718 - 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' );
719 608
720 - if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
721 - if ( recaptchaID ) {
722 - grecaptcha.reset( recaptchaID );
723 - } else {
724 - grecaptcha.reset();
609 + if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
610 + if ( recaptchaID ) {
611 + grecaptcha.reset( recaptchaID );
612 + } else {
613 + grecaptcha.reset();
614 + }
725 615 }
726 - }
727 - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) {
728 - hcaptcha.reset();
729 - }
730 - });
616 + });
731 617
732 - jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
618 + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
733 619
734 - fieldset.removeClass( 'frm_doing_ajax' );
735 - scrollToFirstField( object );
620 + fieldset.removeClass( 'frm_doing_ajax' );
621 + scrollToFirstField( object );
736 622
737 - if ( contSubmit ) {
738 - object.submit();
623 + if ( contSubmit ) {
624 + object.submit();
625 + } else {
626 + jQuery( object ).prepend( response.error_message );
627 + checkForErrorsAndMaybeSetFocus();
628 + }
739 629 } else {
740 - jQuery( object ).prepend( response.error_message );
741 - checkForErrorsAndMaybeSetFocus();
742 - }
743 - } else {
744 - // 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
745 631
746 - showFileLoading( object );
632 + showFileLoading( object );
747 633
634 + object.submit();
635 + }
636 + },
637 + error: function() {
638 + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
748 639 object.submit();
749 640 }
750 - };
751 -
752 - error = function() {
753 - jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
754 - object.submit();
755 - };
756 -
757 - postToAjaxUrl( object, data, success, error );
641 + });
758 642 }
759 643
760 - function postToAjaxUrl( form, data, success, error ) {
761 - var ajaxUrl, action, ajaxParams;
762 -
763 - ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase
764 - action = form.getAttribute( 'action' );
765 -
766 - if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
767 - ajaxUrl = action.split( '?action=frm_forms_preview' )[0];
768 - }
769 -
770 - ajaxParams = {
771 - type: 'POST',
772 - url: ajaxUrl,
773 - data: data,
774 - success: success
775 - };
776 -
777 - if ( 'function' === typeof error ) {
778 - ajaxParams.error = error;
779 - }
780 -
781 - jQuery.ajax( ajaxParams );
782 - }
783 -
784 644 function afterFormSubmitted( object, response ) {
785 645 var formCompleted = jQuery( response.content ).find( '.frm_message' );
786 646 if ( formCompleted.length ) {
787 647 jQuery( document ).trigger( 'frmFormComplete', [ object, response ]);
@@ -847,9 +707,9 @@
847 707 return kvp.join( '&' );
848 708 }
849 709
850 710 function addFieldError( $fieldCont, key, jsErrors ) {
851 - var input, id, describedBy, roleString;
711 + var input, id, describedBy;
852 712 if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) {
853 713 $fieldCont.addClass( 'frm_blank_field' );
854 714 input = $fieldCont.find( 'input, select, textarea' );
855 715 id = 'frm_error_field_' + key;
@@ -862,22 +722,16 @@
862 722 $fieldCont.append(
863 723 jsErrors[key]
864 724 );
865 725 } else {
866 - roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
867 - $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
726 + $fieldCont.append( '<div class="frm_error" id="' + id + '">' + jsErrors[key] + '</div>' );
868 727 }
869 728
870 729 if ( typeof describedBy === 'undefined' ) {
871 730 describedBy = id;
872 - } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) {
873 - if ( input.data( 'error-first' ) === 0 ) {
874 - describedBy = describedBy + ' ' + id;
875 - } else {
876 - describedBy = id + ' ' + describedBy;
877 - }
731 + } else if ( describedBy.indexOf( id ) === -1 ) {
732 + describedBy = describedBy + ' ' + id;
878 733 }
879 -
880 734 input.attr( 'aria-describedby', describedBy );
881 735 }
882 736 input.attr( 'aria-invalid', true );
883 737
@@ -893,9 +747,8 @@
893 747
894 748 $fieldCont.removeClass( 'frm_blank_field has-error' );
895 749 errorMessage.remove();
896 750 input.attr( 'aria-invalid', false );
897 - input.removeAttr( 'aria-describedby' );
898 751
899 752 if ( typeof describedBy !== 'undefined' ) {
900 753 describedBy = describedBy.replace( errorId, '' );
901 754 input.attr( 'aria-describedby', describedBy );
@@ -1010,14 +863,14 @@
1010 863 label.append( '<span class="frm-wait"></span>' );
1011 864
1012 865 jQuery.ajax({
1013 866 type: 'POST',
1014 - url: frm_js.ajax_url, // eslint-disable-line camelcase
867 + url: frm_js.ajax_url,
1015 868 data: {
1016 869 action: 'frm_entries_send_email',
1017 870 entry_id: entryId,
1018 871 form_id: formId,
1019 - nonce: frm_js.nonce // eslint-disable-line camelcase
872 + nonce: frm_js.nonce
1020 873 },
1021 874 success: function( msg ) {
1022 875 var admin = document.getElementById( 'wpbody' );
1023 876 if ( admin === null ) {
@@ -1055,9 +908,32 @@
1055 908 /**********************************************
1056 909 * Fallback functions
1057 910 *********************************************/
1058 911
1059 - 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() {
1060 936 if ( typeof String.prototype.trim !== 'function' ) {
1061 937 String.prototype.trim = function() {
1062 938 return this.replace( /^\s+|\s+$/g, '' );
1063 939 };
@@ -1063,9 +939,9 @@
1063 939 };
1064 940 }
1065 941 }
1066 942
1067 - function addFilterFallbackForIE() {
943 + function addFilterFallbackForIE8() {
1068 944 var t, len, res, thisp, i, val;
1069 945
1070 946 if ( ! Array.prototype.filter ) {
1071 947
@@ -1096,8 +972,26 @@
1096 972 };
1097 973 }
1098 974 }
1099 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 +
1100 994 /**
1101 995 * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1102 996 * If this is a match, the User is autofilling the input on a Webkit browser.
1103 997 * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
@@ -1108,38 +1002,8 @@
1108 1002 this.parentNode.removeChild( this );
1109 1003 }
1110 1004 }
1111 1005
1112 - function maybeMakeHoneypotFieldsUntabbable() {
1113 - document.addEventListener( 'keydown', handleKeyUp );
1114 -
1115 - function handleKeyUp( event ) {
1116 - var code;
1117 -
1118 - if ( 'undefined' !== typeof event.key ) {
1119 - code = event.key;
1120 - } else if ( 'undefined' !== typeof event.keyCode && 9 === event.keyCode ) {
1121 - code = 'Tab';
1122 - }
1123 -
1124 - if ( 'Tab' === code ) {
1125 - makeHoneypotFieldsUntabbable();
1126 - document.removeEventListener( 'keydown', handleKeyUp );
1127 - }
1128 - }
1129 -
1130 - function makeHoneypotFieldsUntabbable() {
1131 - document.querySelectorAll( '.frm_verify' ).forEach(
1132 - function( wrapper ) {
1133 - var input = wrapper.querySelector( 'input[id^=frm_email]' );
1134 - if ( input ) {
1135 - input.setAttribute( 'tabindex', -1 );
1136 - }
1137 - }
1138 - );
1139 - }
1140 - }
1141 -
1142 1006 /**
1143 1007 * Focus on the first sub field when clicking to the primary label of combo field.
1144 1008 *
1145 1009 * @since 4.10.02
@@ -1144,11 +1008,11 @@
1144 1008 *
1145 1009 * @since 4.10.02
1146 1010 */
1147 1011 function changeFocusWhenClickComboFieldLabel() {
1148 - var label;
1012 + let label;
1149 1013
1150 - var comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1014 + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1151 1015 comboInputsContainer.forEach( function( inputsContainer ) {
1152 1016 if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1153 1017 return;
1154 1018 }
@@ -1166,12 +1030,8 @@
1166 1030
1167 1031 function checkForErrorsAndMaybeSetFocus() {
1168 1032 var errors, element, timeoutCallback;
1169 1033
1170 - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase
1171 - return;
1172 - }
1173 -
1174 1034 errors = document.querySelectorAll( '.frm_form_field .frm_error' );
1175 1035 if ( ! errors.length ) {
1176 1036 return;
1177 1037 }
@@ -1205,217 +1065,10 @@
1205 1065 }
1206 1066 } while ( element.previousSibling );
1207 1067 }
1208 1068
1209 - /**
1210 - * Checks if is on IE browser.
1211 - *
1212 - * @since 5.4
1213 - *
1214 - * @return {Boolean}
1215 - */
1216 - function isIE() {
1217 - return navigator.userAgent.indexOf( 'MSIE' ) > -1 || navigator.userAgent.indexOf( 'Trident' ) > -1;
1218 - }
1219 -
1220 - /**
1221 - * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
1222 - *
1223 - * @since 5.4
1224 - *
1225 - * @param {String} event Event name.
1226 - * @param {String} selector Selector.
1227 - * @param {Function} handler Handler.
1228 - * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`.
1229 - */
1230 - function documentOn( event, selector, handler, options ) {
1231 - if ( 'undefined' === typeof options ) {
1232 - options = false;
1233 - }
1234 -
1235 - document.addEventListener( event, function( e ) {
1236 - var target;
1237 -
1238 - // loop parent nodes from the target to the delegation node.
1239 - for ( target = e.target; target && target != this; target = target.parentNode ) {
1240 - if ( target && target.matches && target.matches( selector ) ) {
1241 - handler.call( target, e );
1242 - break;
1243 - }
1244 - }
1245 - }, options );
1246 - }
1247 -
1248 - function initFloatingLabels() {
1249 - var checkFloatLabel, checkDropdownLabel, checkPlaceholderIE, runOnLoad, selector, floatClass;
1250 -
1251 - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1252 - floatClass = 'frm_label_float_top';
1253 -
1254 - checkFloatLabel = function( input ) {
1255 - var container, shouldFloatTop, firstOpt;
1256 -
1257 - container = input.closest( '.frm_inside_container' );
1258 - if ( ! container ) {
1259 - return;
1260 - }
1261 -
1262 - shouldFloatTop = input.value || document.activeElement === input;
1263 -
1264 - container.classList.toggle( floatClass, shouldFloatTop );
1265 -
1266 - if ( 'SELECT' === input.tagName ) {
1267 - firstOpt = input.querySelector( 'option:first-child' );
1268 -
1269 - if ( shouldFloatTop ) {
1270 - if ( firstOpt.hasAttribute( 'data-label' ) ) {
1271 - firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
1272 - firstOpt.removeAttribute( 'data-label' );
1273 - }
1274 - } else {
1275 - if ( firstOpt.textContent ) {
1276 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1277 - firstOpt.textContent = '';
1278 - }
1279 - }
1280 - } else if ( isIE() ) {
1281 - checkPlaceholderIE( input );
1282 - }
1283 - };
1284 -
1285 - checkDropdownLabel = function() {
1286 - document.querySelectorAll( '.frm-show-form .frm_inside_container:not(.' + floatClass + ') select' ).forEach( function( input ) {
1287 - var firstOpt = input.querySelector( 'option:first-child' );
1288 -
1289 - if ( firstOpt.textContent ) {
1290 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1291 - firstOpt.textContent = '';
1292 - }
1293 - });
1294 - };
1295 -
1296 - checkPlaceholderIE = function( input ) {
1297 - if ( input.value ) {
1298 - // Don't need to handle this case because placeholder isn't shown.
1299 - return;
1300 - }
1301 -
1302 - if ( document.activeElement === input ) {
1303 - if ( input.hasAttribute( 'data-placeholder' ) ) {
1304 - input.placeholder = input.getAttribute( 'data-placeholder' );
1305 - input.removeAttribute( 'data-placeholder' );
1306 - }
1307 - } else {
1308 - if ( input.placeholder ) {
1309 - input.setAttribute( 'data-placeholder', input.placeholder );
1310 - input.placeholder = '';
1311 - }
1312 - }
1313 - };
1314 -
1315 - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
1316 - documentOn(
1317 - eventName,
1318 - selector,
1319 - function( event ) {
1320 - checkFloatLabel( event.target );
1321 - },
1322 - true
1323 - );
1324 - });
1325 -
1326 - jQuery( document ).on( 'change', selector, function( event ) {
1327 - checkFloatLabel( event.target );
1328 - });
1329 -
1330 - runOnLoad = function( firstLoad ) {
1331 - if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) {
1332 - checkFloatLabel( document.activeElement );
1333 - } else if ( firstLoad ) {
1334 - document.querySelectorAll( '.frm_inside_container' ).forEach(
1335 - function( container ) {
1336 - var input = container.querySelector( 'input, select, textarea' );
1337 - if ( input && '' !== input.value ) {
1338 - checkFloatLabel( input );
1339 - }
1340 - }
1341 - );
1342 - }
1343 -
1344 - checkDropdownLabel();
1345 -
1346 - if ( isIE() ) {
1347 - document.querySelectorAll( selector ).forEach( function( input ) {
1348 - checkPlaceholderIE( input );
1349 - });
1350 - }
1351 - };
1352 -
1353 - runOnLoad( true );
1354 -
1355 - jQuery( document ).on( 'frmPageChanged', function( event ) {
1356 - runOnLoad();
1357 - });
1358 -
1359 - document.addEventListener( 'frm_after_start_over', function( event ) {
1360 - runOnLoad();
1361 - });
1362 - }
1363 -
1364 - function maybeShowNewTabFallbackMessage() {
1365 - var messageEl;
1366 -
1367 - if ( ! window.frmShowNewTabFallback ) {
1368 - return;
1369 - }
1370 -
1371 - messageEl = document.querySelector( '#frm_form_' + frmShowNewTabFallback.formId + '_container .frm_message' );
1372 - if ( ! messageEl ) {
1373 - return;
1374 - }
1375 -
1376 - messageEl.insertAdjacentHTML( 'beforeend', ' ' + frmShowNewTabFallback.message );
1377 - }
1378 -
1379 - function setCustomValidityMessage() {
1380 - var forms, length, index;
1381 -
1382 - forms = document.getElementsByClassName( 'frm-show-form' );
1383 - length = forms.length;
1384 -
1385 - for ( index = 0; index < length; ++index ) {
1386 - forms[ index ].addEventListener(
1387 - 'invalid',
1388 - function( event ) {
1389 - var target = event.target;
1390 -
1391 - if ( 'INPUT' !== target.nodeName ) {
1392 - return;
1393 - }
1394 -
1395 - if ( ! target.dataset.invmsg ) {
1396 - return;
1397 - }
1398 -
1399 - if ( 'text' !== target.getAttribute( 'type' ) ) {
1400 - return;
1401 - }
1402 -
1403 - if ( target.classList.contains( 'frm_verify' ) ) {
1404 - return;
1405 - }
1406 -
1407 - target.setCustomValidity( target.dataset.invmsg );
1408 - },
1409 - true
1410 - );
1411 - }
1412 - }
1413 -
1414 1069 return {
1415 1070 init: function() {
1416 - maybeAddPolyfills();
1417 -
1418 1071 jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1419 1072 jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
1420 1073
1421 1074 jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
@@ -1430,11 +1083,11 @@
1430 1083
1431 1084 jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail );
1432 1085
1433 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 );
1434 1088
1435 1089 jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange );
1436 - maybeMakeHoneypotFieldsUntabbable();
1437 1090
1438 1091 jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick );
1439 1092 jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv );
1440 1093
@@ -1442,17 +1095,13 @@
1442 1095
1443 1096 // Focus on the first sub field when clicking to the primary label of combo field.
1444 1097 changeFocusWhenClickComboFieldLabel();
1445 1098
1446 - // Add fallbacks for IE.
1447 - addTrimFallbackForIE(); // Trim only works in IE10+.
1448 - addFilterFallbackForIE(); // Filter is not supported in any version of IE.
1449 -
1450 - initFloatingLabels();
1451 - maybeShowNewTabFallbackMessage();
1452 -
1453 - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
1454 - setCustomValidityMessage();
1099 + // Add fallbacks for the beloved IE8
1100 + addIndexOfFallbackForIE8();
1101 + addTrimFallbackForIE8();
1102 + addFilterFallbackForIE8();
1103 + addKeysFallbackForIE8();
1455 1104 },
1456 1105
1457 1106 getFieldId: function( field, fullID ) {
1458 1107 return getFieldId( field, fullID );
@@ -1635,12 +1284,12 @@
1635 1284 removeSubmitLoading: function( $object, enable, processesRunning ) {
1636 1285 removeSubmitLoading( $object, enable, processesRunning );
1637 1286 },
1638 1287
1639 - scrollToID: function( id ) {
1640 - var object = jQuery( document.getElementById( id ) );
1641 - frmFrontForm.scrollMsg( object, false );
1642 - },
1288 + scrollToID: function( id ) {
1289 + var object = jQuery( document.getElementById( id ) );
1290 + frmFrontForm.scrollMsg( object, false );
1291 + },
1643 1292
1644 1293 scrollMsg: function( id, object, animate ) {
1645 1294 var newPos, m, b, screenTop, screenBottom,
1646 1295 scrollObj = '';
@@ -1656,12 +1305,12 @@
1656 1305 }
1657 1306
1658 1307 jQuery( scrollObj ).trigger( 'focus' );
1659 1308 newPos = scrollObj.offset().top;
1660 - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase
1309 + if ( ! newPos || frm_js.offset === '-1' ) {
1661 1310 return;
1662 1311 }
1663 - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase
1312 + newPos = newPos - frm_js.offset;
1664 1313
1665 1314 m = jQuery( 'html' ).css( 'margin-top' );
1666 1315 b = jQuery( 'body' ).css( 'margin-top' );
1667 1316 if ( m || b ) {
@@ -1698,9 +1347,9 @@
1698 1347
1699 1348 jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]);
1700 1349
1701 1350 if ( e.selfTriggered !== true ) {
1702 - maybeValidateChange( this );
1351 + maybeValidateChange( fieldId, this );
1703 1352 }
1704 1353 },
1705 1354
1706 1355 savingDraft: function( object ) {
@@ -1789,15 +1438,15 @@
1789 1438 function frmUpdateField( entryId, fieldId, value, message, num ) {
1790 1439 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
1791 1440 jQuery.ajax({
1792 1441 type: 'POST',
1793 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1442 + url: frm_js.ajax_url,
1794 1443 data: {
1795 1444 action: 'frm_entries_update_field_ajax',
1796 1445 entry_id: entryId,
1797 1446 field_id: fieldId,
1798 1447 value: value,
1799 - nonce: frm_js.nonce // eslint-disable-line camelcase
1448 + nonce: frm_js.nonce
1800 1449 },
1801 1450 success: function() {
1802 1451 if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
1803 1452 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' );
@@ -1812,13 +1461,13 @@
1812 1461 console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' );
1813 1462 jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
1814 1463 jQuery.ajax({
1815 1464 type: 'POST',
1816 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1465 + url: frm_js.ajax_url,
1817 1466 data: {
1818 1467 action: 'frm_entries_destroy',
1819 1468 entry: entryId,
1820 - nonce: frm_js.nonce // eslint-disable-line camelcase
1469 + nonce: frm_js.nonce
1821 1470 },
1822 1471 success: function( html ) {
1823 1472 if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
1824 1473 jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' );
@@ -1839,14 +1488,14 @@
1839 1488 console.warn( 'DEPRECATED: function frm_resend_email in v2.0' );
1840 1489 $link.append( '<span class="spinner" style="display:inline"></span>' );
1841 1490 jQuery.ajax({
1842 1491 type: 'POST',
1843 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1492 + url: frm_js.ajax_url,
1844 1493 data: {
1845 1494 action: 'frm_entries_send_email',
1846 1495 entry_id: entryId,
1847 1496 form_id: formId,
1848 - nonce: frm_js.nonce // eslint-disable-line camelcase
1497 + nonce: frm_js.nonce
1849 1498 },
1850 1499 success: function( msg ) {
1851 1500 $link.replaceWith( msg );
1852 1501 }