-
Notifications
You must be signed in to change notification settings - Fork 39
Respect constraints on custom element form fields #6
Comments
Any thoughts on displaying a visual notification when a custom element form field is determined to be invalid? Options:
The last two options are a bit kludgey. But, I do like option 3 as we delegate to the browser for the UI (if the browser does provide a UI). With the proper CSS, I suspect we can make this work with option 3. |
My vote is for 1, with an eye for eventually implementing 3. 1 because this is the simplest API and enables the most flexibility to the user. 3 because I think relying on the browser for UI is a good option, if possible. It'd be nice if polymer had a convention for errors on elements... seems like |
ajax-form probably should use a similarly named event. "invalid" is too generic and could possibly collide with another event unrelated to core-ajax. |
It seems reasonable to expect that the custom element will provide it's own markup for exposing validation errors, such as
Regarding the first item, The second item needs further discussion. I believe |
Somewhat dependent on rnicholus/file-input#16. We'll just check an |
Now that
I'll also ensure ajax-form works properly with Polymer 0.4.2. |
Hmm, this is proving to be a bit difficult, at least in Firefox, where, on submit, an invalid |
Further investigation suggests that Firefox is the only browser where an "invalid" event is not triggered (or maybe just not consumable) on form submit if |
Even further investigation shows that this is not a Firefox-specific issue. In fact, it is common to all browsers that do not implement the web components spec. So, in Chrome, if a core-input/paper-element is included in a form field, and the field is invalid, the form submits anyway. In all other browsers, form submission is prevented, but the "invalid" event is either not fired by the underlying input, or it is squelched by platform.js. Next step is to confirm that Polymer is squelching this invalid event and determine why the browser is not seeing the field as invalid in non-polyfilled browsers (Chrome) on form submit. |
Now blocked/dependent on rnicholus/file-input#19. |
|
I have most of this completed in my local workspace. All that's left is a bit more manual testing, some more unit tests, and an update of the docs. I know this works with file-input, but I'll probably modify paper/core-input as well. If that pans out, I'll run a PR past the Polymer folks and see what they think about adopting/promoting these conventions in other custom fields. |
Custom form fields will be validated, assuming they include a hidden input that mirrors the validity of the custom form field. A reference to the CE should be present on the hidden input via a customElementRef property. ref #6
We'll need to pay special attention to
required
attributes on custom elements, such as<file-element>
. These are not standard form fields, so this will be a bit more difficult.The
checkValidity
method on theHTMLFormElement
won't validate custom elements. We'll need to augment this (if possible) or be aware of custom element form fields and implement some convention to determine if anyrequired
custom element form fields are invalid. The other tricky part will be dealing with this in the UI. I'm not sure if there is a way to "trick" the browser into displaying a native validation error message for a custom form field. If not, we'll have to have our own UI to handle this.This is mentioned in rnicholus/file-input#8.
The text was updated successfully, but these errors were encountered: