diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 6248e46efe..6a10f89d95 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -531,6 +531,19 @@ if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) { throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { '!url': ajax.url })); } + let $elem = $(this); + if (typeof $elem.attr('formnovalidate') === 'undefined') { + let formElem = $elem.closest('form')[0]; + if (formElem && !formElem.checkValidity()) { + if (typeof formElem.reportValidity === 'function') { + formElem.reportValidity(); + } + else { + $elem.once(`${event.type}-ajax`).trigger(event.type); + } + return; + } + } return ajax.eventResponse(this, event); }); diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 5ea52425be..3f27293e10 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -252,6 +252,18 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) { throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { '!url': ajax.url })); } + var $elem = $(this); + if (typeof $elem.attr('formnovalidate') === 'undefined') { + var formElem = $elem.closest('form')[0]; + if (formElem && !formElem.checkValidity()) { + if (typeof formElem.reportValidity === 'function') { + formElem.reportValidity(); + } else { + $elem.once(event.type + '-ajax').trigger(event.type); + } + return; + } + } return ajax.eventResponse(this, event); });