Provide native validation messages for native validity states on Form Associated Custom Elements #10360
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: custom elements
Relates to custom elements (as defined in DOM and HTML)
What problem are you trying to solve?
When using Form Associated Custom Elements, you may want to re-use the browser native messages so you don't need to support translations.
What solutions exist today?
Solutions that exist today involve programmatically creating an invalid form control and grabbing its
validationMessage
property.However, there is 1 edge case around
maxlength
andminlength
where you cannot make them invalid without user interaction, so this pattern breaks down for these 2 properties / attributes.The other solution is to do "mirroring" of a form control in your shadow dom, and mirror host attributes onto the shadow dom form control and then grab its
validationMessage
, however, your FACE may not cleanly map to a formControl.for example, a multi-select editable combobox, a contenteditable field in your shadow dom etc.
So in FACE components that need a
maxlength
orminlength
and do not cleanly map to a native form control in their shadow DOM, they have no way to grab the native validation messages.How would you solve it?
Well, this is a 2 part problem.
1.)
maxlength
andminlength
should have a way to programmatically trigger their validations to run, even if thevalue
property was set programmatically.For example:
input.forceCheckValidity()
or similar. I don't know the right answer. This is less of a concern to me.2.) Some way to grab native validation strings.
We could overwrite
setValidity()
so if you passnull
as a second argument, it can perform the native validation message lookup. For example:TLDR: I would love a way to provide native translation strings for native error states like
tooShort
,tooLong
,stepMismatch
, etc.Anything else?
My final goal is to be able to have native validation strings on Form Associated Custom Elements. I'm open to other suggestions and not tied to any particular suggestion here. Thank you for your time and help!
The text was updated successfully, but these errors were encountered: