openui / open-ui

Maintain an open standard for UI and promote its adherence and adoption.
https://open-ui.org
Other
3.4k stars 183 forks source link

Errors for form related controls #802

Open gregwhitworth opened 11 months ago

gregwhitworth commented 11 months ago

I've been meaning to file this issue as we do need a resolution to this prior to <selectlist> shipping. HTML has a few capabilities to enable client-side validation upon form submission; such as the required attribute. UAs have full control over the anatomy and rendering since like most UI this is not standardized anywhere. For example here are a few renderings when submitted a form that is required.

Screenshot 2023-08-16 at 10 42 19 AM Screenshot 2023-08-16 at 10 40 55 AM Screenshot 2023-08-16 at 10 40 27 AM

A solution to this will warrant its own explainer, so that is not the goal of this issue; the purpose of this issue is to answer the following question:

Is the error related to client-side validation a part of the anatomy of the control that owns the given attribute.

To provide a concrete example, let's use <selectlist> with a straw proposal for an <error> element:

<selectlist required>
   ... rest of anatomy here ...
   <requirederror>This field is required</requirederror>
   <patternerror>The field does not match the given pattern</patternerror><!-- this won't fire in this scenario since a pattern wasn't set -->
</selectlist>

I'm personally leaning towards doing a binding solution akin to the popover API and as I noted a research document will need to be created to influence the solution but that provides the following:

  1. It doesn't block <selectlist> due to potential backwards compat issues
  2. It allows scenarios where it isn't a part of the anatomy but is positioned relative to the offending field (another need for anchor-position)
  3. Universal "stamping" of solutions rather than needing to replicate it for every HTML element
css-meeting-bot commented 10 months ago

The Open UI Community Group just discussed Errors for form related controls, and agreed to the following:

The full IRC log of that discussion <Luke> q-
<jarhar> gregw: selectlist is closer so i need to raise it to make sure we dont lose it. errors are usually associated, required or pattern
<jarhar> gregw: its related to invokertarget thing, a solution could fall out of that
<jarhar> gregw: if im looking at how a lot of design systems do that, its already right within the element
<jarhar> gregw: i dont think thats how were going to do selectlist
<jarhar> gregw: most of the browsers do it in the shadowdom? someone can correct me. it may vary by control
<jarhar> gregw: to look at salesforce. success is you get a toolbar across the top, but if theres errors its inline with the input
<masonf> q+
<jarhar> gregw: i just want to raise the scenario that people are going to want to style these things that get rendered, and we dont have control over that, and to devs thats part of that anatomy
<jarhar> gregw: i want to make these 3 look like my design system
<jarhar> gregw: i dont have a solution, but one thing i would want to avoid is just have it auto stamp out everywhere, so i dont have to by default change that specifc elements failure text i can, but in most scenarios i wouldnt want to
<Luke> q+
<jarhar> gregw: its an interesting problem space before we cement selectlist, it would be cool to go back and say we know for sure we dont want it in the anatomy. if we do, then we need to figure it out now
<jarhar> masonf: we dont want it in the anatomy
<jarhar> masonf: implementation wise, in all browsers they are not in the renderer, its in the browser, separate OS window, not stylable to the control
<gregwhitworth> q+
<jarhar> masonf: not that this is ideal, there is a request in whatwg to be able to style those validation bubbles
<gregwhitworth> ack masonf
<jarhar> masonf: i would like to separate that out so that we solve that independently and separately from selectlist
<jarhar> masonf: i dont think that the solution for that requires you to incorporate it into the anatomy
<jarhar> masonf: we are proposing a way to style that without saying its really part of the element
<jarhar> masonf: i dont think we should block on this and i dont think we should include it in the anatomy
<gregwhitworth> ack Luke
<jarhar> lukew: just from an ideas point of view, likewise with the tooltip, these to me seem like popovers. obviously right now they are native ui, but they seem like a thing that just an error popover, but it would be separate from the selectlist
<jarhar> lukew: you could invoke one popover from each input
<jarhar> lukew: likewise with tooltips, it would be a popover of interest rather one that invokes
<jarhar> gregw: what was in my brain was having a definition in the dom and its declarative
<jarhar> gregw: its part of the anatomy, but now its not part of the anatomy. i appreciate the tooltip one, pseudo elements are good but they are limited
<jarhar> gregw: just a square thats flat, i want to replace the content at that point, not just change colors and border
<jarhar> gregw: certain tonality that i use for them, and the localization
<jarhar> gregw: im intrigued that the invoker paradigm, because its accomplishing the same goal
<jarhar> gregw: on submit, invoker wont work, and ironically this is when that all takes place
<jarhar> gregw: we just need to do the magic behind the scenes, if this type of pattern invoker whatever element, some magical thing, the browser knows to go find that, if theres a global one or an idref
<jarhar> gregw: i got what i wanted out of this, which is dont block selectlist, it should be generalized and not part of the anatomy
<jarhar> masonf: are you ok with a resolution of that?
<jarhar> gregw: yes, give me a solution but not in the selectlist anatomy
<masonf> Proposed resolution: this is a good problem to solve, but it's independent of the <selectlist>
<masonf> q?
<Luke> +1
<masonf> ack greg
<bkardell_> +1
<jarhar> bkardell: it was more than selectlist, as a rule, but thats fine
<masonf> RESOLVED: this is a good problem to solve, but it's independent of the <selectlist>. We should solve this generally.
gregwhitworth commented 10 months ago

I've started a draft explainer and research in this Google doc for this since it's going to be a pretty complex problem.

scottaohara commented 10 months ago

some quick thoughts to consider - some of which border/veer into 'solutions' but that's more just due to me wanting to get the ideas out, rather than trying to imply 'do it this way':

lukewarlow commented 5 months ago

https://x.com/RogersKonnor/status/1753788382059118952?s=20

This raises an interesting idea? What if we provided an mechanism to get the language strings for a given error message? That way the UI could be completely up to userland?

jpzwarte commented 5 months ago

Perhaps also related to this issue: https://github.com/whatwg/html/issues/9878

There is no currently no way for a Form Associated Custom Element to know it is supposed to report its validity. It only receives an invalid event when its validity is not valid.