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); });