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

feat: add calciteInvalid event #9211

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,16 @@ export function formAssociated(

const submitButton = await page.find("#submitButton");
const spyEvent = await page.spyOnEvent(getClearValidationEventName(tag));
const spyInvalidEvent = await page.spyOnEvent("calciteInvalid");

await assertPreventsFormSubmission(page, component, submitButton, requiredValidationMessage);
expect(spyInvalidEvent).toHaveReceivedEventTimes(1);

await assertClearsValidationOnValueChange(page, component, options, spyEvent, tag);
expect(spyInvalidEvent).toHaveReceivedEventTimes(1);

await assertUserMessageNotOverridden(page, component, submitButton);
expect(spyInvalidEvent).toHaveReceivedEventTimes(2);
}

function ensureName(html: string, componentTag: string): string {
Expand Down
3 changes: 3 additions & 0 deletions packages/calcite-components/src/utils/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ function displayValidationMessage(event: Event) {
// prevent the browser from showing the native validation popover
event?.preventDefault();

// dispatch a "calciteInvalid" so users can set custom validation messages
formComponent.dispatchEvent(new CustomEvent("calciteInvalid", { bubbles: true, composed: true }));

setInvalidFormValidation(formComponent, hiddenInput?.validationMessage);

if (formComponent?.validationMessage !== hiddenInput?.validationMessage) {
Expand Down
Loading