Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect novalidate and do not check validation or stop submission. #3543

Merged
merged 1 commit into from
Jun 10, 2016
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
3 changes: 2 additions & 1 deletion src/document-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ 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
// the submit event wouldn't be fired if the form is invalid.
// 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;
}
Expand Down
8 changes: 8 additions & 0 deletions test/functional/test-document-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down