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

Is there any option to customize the validation message for input fields? #53

Open
manusimelabs opened this issue Jul 31, 2023 · 3 comments

Comments

@manusimelabs
Copy link

We can pass the required flag to the input field and it is showing the default browser html validation message. Is there any option to get the errors in the submit event so that we can show the error messages based on our styles?

@sidharthramesh
Copy link
Collaborator

Hey @manusimelabs, the way this currently works is by triggering the "reportValidity" method on each element. And this method will halt the submission process if there are any validation errors - https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reportValidity

However, I believe your use case is very valid. Have any ideas on how we can go about implementing this?

@manusimelabs
Copy link
Author

Hi @sidharthramesh, Thanks for responding.

I am trying to customize the validation error styles and messages. https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation#Constraint_API%27s_element.setCustomValidity().

I will update here if I get any solution.

@manusimelabs
Copy link
Author

@sidharthramesh Is it possible to create a custom 'mb-invalid' event similar to the 'invalid' event of HTMLInputElement?
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event.
Handling this custom event could allow us to perform custom validation and error message display instead of relying on default validation behavior.

Additionally, what is the recommended way to style inputs within a shadow DOM? As external styles typically don't affect the shadow DOM's internal elements directly, is there a way to customize the input styles in this scenario (Example. What can I do to add a border around the inputs)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants