Skip to content

Commit ff33b37

Browse files
fix: respect novalidate
1 parent 3ca453e commit ff33b37

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Diff for: src/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export const formSubmitCallback = (event: Event) => {
132132
const form = event.target as HTMLFormElement;
133133
const elements = formElementsMap.get(form);
134134

135+
/**
136+
* If this form does not validate then we're done
137+
*/
138+
if (form.noValidate) {
139+
return;
140+
}
141+
135142
/** If the Set has items, continue */
136143
if (elements.size) {
137144
const nodes = Array.from(elements);

Diff for: test/ElementInternals.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,25 @@ describe('The ElementInternals polyfill', () => {
510510
expect(callCount).to.equal(1);
511511
});
512512
});
513+
514+
describe('Forms with novalidate', () => {
515+
it('will not block submit', async () => {
516+
let submitCount = 0;
517+
const onSubmit = (event) => {
518+
event.preventDefault();
519+
submitCount += 1;
520+
}
521+
const form = await fixture(html`<form novalidate @submit="${onSubmit}">
522+
<test-el name="foo" id="foo"></test-el>
523+
<button type="submit">Submit</button>
524+
</form>`);
525+
const testEl = form.querySelector('test-el');
526+
const button = form.querySelector('button');
527+
testEl.internals.setValidity({
528+
customError: true
529+
}, 'error message');
530+
button.click();
531+
expect(submitCount).to.equal(1);
532+
});
533+
});
513534
});

0 commit comments

Comments
 (0)