From 0a59b72b6e20e596cf5967b7b7642dcc458da8c7 Mon Sep 17 00:00:00 2001 From: Mohammad Khatib Date: Fri, 10 Jun 2016 14:45:37 -0700 Subject: [PATCH] Respect novalidate and do not check validation or stop submission. --- src/document-submit.js | 3 ++- test/functional/test-document-submit.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/document-submit.js b/src/document-submit.js index c5b326d22c01..d7b9ff035f2f 100644 --- a/src/document-submit.js +++ b/src/document-submit.js @@ -54,6 +54,7 @@ export function onDocumentFormSubmit_(e) { user.assert(target, 'form target attribute is required: %s', form); user.assert(target == '_blank' || target == '_top', 'form target=%s is invalid can only be _blank or _top: %s', target, form); + const shouldValidate = !form.hasAttribute('novalidate'); // Safari does not trigger validation check on submission, hence we // trigger it manually. In other browsers this would never execute since @@ -61,7 +62,7 @@ export function onDocumentFormSubmit_(e) { // TODO: This doesn't display the validation error messages. Safari makes them // available per input.validity object. We need to figure out a way of // displaying these. - if (form.checkValidity && !form.checkValidity()) { + if (shouldValidate && form.checkValidity && !form.checkValidity()) { e.preventDefault(); return; } diff --git a/test/functional/test-document-submit.js b/test/functional/test-document-submit.js index 812a0e296b66..1c2bc6b54e5f 100644 --- a/test/functional/test-document-submit.js +++ b/test/functional/test-document-submit.js @@ -97,6 +97,14 @@ describe('test-document-submit onDocumentFormSubmit_', () => { expect(tgt.checkValidity.callCount).to.equal(1); }); + it('should not check validity if novalidate provided', () => { + tgt.setAttribute('novalidate', ''); + tgt.checkValidity = sandbox.stub().returns(false); + onDocumentFormSubmit_(evt); + expect(preventDefaultSpy.callCount).to.equal(0); + expect(tgt.checkValidity.callCount).to.equal(0); + }); + it('should not prevent default', () => { tgt.checkValidity = sandbox.stub().returns(true); onDocumentFormSubmit_(evt);