Skip to content

Commit

Permalink
fix: handle form submit and novalidate (#6123)
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonio authored Feb 26, 2024
2 parents d056d92 + b643ab2 commit d76e3c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/components/src/components/form/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ export const propagateSubmitEventToForm = (
if (form.tagName === 'FORM') {
setEventTarget(event, form);
form.dispatchEvent(event);
(form as HTMLFormElement).submit();
if (getExperimentalMode() && (form as HTMLFormElement).noValidate === false) {
devHint(`If you have not focusable or hidden form fields in your form, you should enable noValidate for your form.`, {
force: true,
});
// (form as HTMLFormElement).noValidate = true; do not make this implicit
}
if (typeof (form as HTMLFormElement).requestSubmit === 'function') {
// See https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit
(form as HTMLFormElement).requestSubmit();
}
} else if (form.tagName === 'KOL-FORM') {
setEventTarget(event, KoliBriDevHelper.querySelector('form', form) as HTMLFormElement);
const kolForm = form as Props;
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/utils/a11y.tipps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const a11yHint = (msg: string, options?: HintOptions): void => {
a11yCache.add(msg);
Log.debug(([msg] as unknown[]).concat(options?.details || []), {
classifier: `✋ a11y`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #09f',
});
}
Expand All @@ -22,6 +23,7 @@ export const deprecatedHint = (msg: string, options?: HintOptions): void => {
deprecatedCache.add(msg);
Log.warn(([msg] as unknown[]).concat(options?.details || []), {
classifier: `🔥 deprecated`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #f00',
});
}
Expand All @@ -33,6 +35,7 @@ export const devHint = (msg: string, options?: HintOptions): void => {
devCache.add(msg);
Log.debug(([msg] as unknown[]).concat(options?.details || []), {
classifier: `💻 dev`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #f09',
});
}
Expand All @@ -41,7 +44,8 @@ export const devWarning = (msg: string, options?: HintOptions): void => {
if (devCache.has(msg) === false || !!options?.force) {
devCache.add(msg);
Log.warn(([msg] as unknown[]).concat(options?.details || []), {
classifier: `💻 dev`,
classifier: `⚠️ dev`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #f09',
});
}
Expand All @@ -54,6 +58,7 @@ export const featureHint = (msg: string, done = false, options?: HintOptions): v
msg += done === true ? ' ✅' : '';
Log.debug(([msg] as unknown[]).concat(options?.details || []), {
classifier: `🌟 feature`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #309',
});
}
Expand All @@ -68,6 +73,7 @@ export const uiUxHint = (msg: string, options?: HintOptions): void => {
uiUxCache.add(msg);
Log.debug(([msg] as unknown[]).concat(options?.details || []), {
classifier: `📑 ui/ux`,
forceLog: !!options?.force,
overwriteStyle: '; background-color: #060;',
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/samples/react/src/scenarios/static-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const StaticForm: FC = () => {
</li>
</ol>
</SampleDescription>
<form className="grid gap-4" method="get">
<form className="grid gap-4" method="get" noValidate>
<KolInputCheckbox _name="checkbox" _label="Checkbox" />
<KolInputColor _name="color" _label="Color" />
<KolInputDate _name="date" _label="Date" />
Expand Down

0 comments on commit d76e3c1

Please sign in to comment.