Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 55 additions & 16 deletions js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function frmFrontFormJS() {
* @since 5.4
*/
function maybeAddPolyfills() {
var i;
if ( ! Element.prototype.matches ) {
// IE9 supports matches but as msMatchesSelector instead.
Element.prototype.matches = Element.prototype.msMatchesSelector;
Expand All @@ -41,7 +42,7 @@ function frmFrontFormJS() {
if ( window.NodeList && ! NodeList.prototype.forEach ) {
NodeList.prototype.forEach = function( callback, thisArg ) {
thisArg = thisArg || window;
for ( var i = 0; i < this.length; i++ ) {
for ( i = 0; i < this.length; i++ ) {
callback.call( thisArg, this[ i ], i, this );
}
};
Expand Down Expand Up @@ -585,7 +586,7 @@ function frmFrontFormJS() {
fieldset = jQuery( object ).find( '.frm_form_field' );
fieldset.addClass( 'frm_doing_ajax' );

data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce;
data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase
shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );

success = function( response ) {
Expand Down Expand Up @@ -626,7 +627,7 @@ function frmFrontFormJS() {
}

removeSubmitLoading( jQuery( object ) );
if ( frm_js.offset != -1 ) {
if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase
frmFrontForm.scrollMsg( jQuery( object ), false );
}

Expand Down Expand Up @@ -746,7 +747,7 @@ function frmFrontFormJS() {
function postToAjaxUrl( form, data, success, error ) {
var ajaxUrl, action, ajaxParams;

ajaxUrl = frm_js.ajax_url;
ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase
action = form.getAttribute( 'action' );

if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
Expand Down Expand Up @@ -849,7 +850,7 @@ function frmFrontFormJS() {
jsErrors[key]
);
} else {
roleString = frm_js.include_alert_role ? 'role="alert"' : '';
roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
$fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
}

Expand Down Expand Up @@ -997,12 +998,12 @@ function frmFrontFormJS() {

jQuery.ajax({
type: 'POST',
url: frm_js.ajax_url,
url: frm_js.ajax_url, // eslint-disable-line camelcase
data: {
action: 'frm_entries_send_email',
entry_id: entryId,
form_id: formId,
nonce: frm_js.nonce
nonce: frm_js.nonce // eslint-disable-line camelcase
},
success: function( msg ) {
var admin = document.getElementById( 'wpbody' );
Expand Down Expand Up @@ -1153,7 +1154,7 @@ function frmFrontFormJS() {
function checkForErrorsAndMaybeSetFocus() {
var errors, element, timeoutCallback;

if ( ! frm_js.focus_first_error ) {
if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase
return;
}

Expand Down Expand Up @@ -1347,6 +1348,41 @@ function frmFrontFormJS() {
});
}

function setCustomValidityMessage() {
var forms, length, index;

forms = document.getElementsByClassName( 'frm-show-form' );
length = forms.length;

for ( index = 0; index < length; ++index ) {
forms[ index ].addEventListener(
'invalid',
function( event ) {
var target = event.target;

if ( 'INPUT' !== target.nodeName ) {
return;
}

if ( ! target.dataset.invmsg ) {
return;
}

if ( 'text' !== target.getAttribute( 'type' ) ) {
return;
}

if ( target.classList.contains( 'frm_verify' ) ) {
return;
}

target.setCustomValidity( target.dataset.invmsg );
},
true
);
}
}

return {
init: function() {
maybeAddPolyfills();
Expand Down Expand Up @@ -1384,6 +1420,9 @@ function frmFrontFormJS() {
addFilterFallbackForIE(); // Filter is not supported in any version of IE.

initFloatingLabels();

jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
setCustomValidityMessage();
},

getFieldId: function( field, fullID ) {
Expand Down Expand Up @@ -1589,10 +1628,10 @@ function frmFrontFormJS() {

jQuery( scrollObj ).trigger( 'focus' );
newPos = scrollObj.offset().top;
if ( ! newPos || frm_js.offset === '-1' ) {
if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase
return;
}
newPos = newPos - frm_js.offset;
newPos = newPos - frm_js.offset; // eslint-disable-line camelcase

m = jQuery( 'html' ).css( 'margin-top' );
b = jQuery( 'body' ).css( 'margin-top' );
Expand Down Expand Up @@ -1722,13 +1761,13 @@ function frmUpdateField( entryId, fieldId, value, message, num ) {
jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
jQuery.ajax({
type: 'POST',
url: frm_js.ajax_url,
url: frm_js.ajax_url, // eslint-disable-line camelcase
data: {
action: 'frm_entries_update_field_ajax',
entry_id: entryId,
field_id: fieldId,
value: value,
nonce: frm_js.nonce
nonce: frm_js.nonce // eslint-disable-line camelcase
},
success: function() {
if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
Expand All @@ -1745,11 +1784,11 @@ function frmDeleteEntry( entryId, prefix ) {
jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
jQuery.ajax({
type: 'POST',
url: frm_js.ajax_url,
url: frm_js.ajax_url, // eslint-disable-line camelcase
data: {
action: 'frm_entries_destroy',
entry: entryId,
nonce: frm_js.nonce
nonce: frm_js.nonce // eslint-disable-line camelcase
},
success: function( html ) {
if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
Expand All @@ -1772,12 +1811,12 @@ function frm_resend_email( entryId, formId ) { // eslint-disable-line camelcase
$link.append( '<span class="spinner" style="display:inline"></span>' );
jQuery.ajax({
type: 'POST',
url: frm_js.ajax_url,
url: frm_js.ajax_url, // eslint-disable-line camelcase
data: {
action: 'frm_entries_send_email',
entry_id: entryId,
form_id: formId,
nonce: frm_js.nonce
nonce: frm_js.nonce // eslint-disable-line camelcase
},
success: function( msg ) {
$link.replaceWith( msg );
Expand Down
Loading