Need callback for form submit data #187
Comments
Here is my proposal for addressing this issue: http://dave-ford.blogspot.com/2016/06/web-components-and-form-submit-fields.html |
Custom elements F2F: we would like this! Previously, https://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0448.html Current thinking is:
|
The last point is why we decided to use string & JSON for the value so that we can use Using Yet anther option is to let users of component specify names for each value the component supplies but this is very different from the way builtin elements work so probably not a good idea. |
@domenic if it is |
Yes |
Awesome. But since you tagged it v2: If it does come into the specs it will probably be a year or more, correct? Since v1 is just releases and not even really implemented anywhere. |
No, "v2" is a misnomer. The specs are living and see continuous changes, and implementations implement those changes as they can prioritize them, according to each implementation's individual release cycle. In the issue tracker, "v2" means something roughly like "not part of the initial set of features that we reached consensus on in the January 2016 face to face meeting". |
Ahh, I see. Thanks for the clarification. Where can I best track the progress of this, to see if/when it will come? |
Watching this issue is the best way to get updated on spec progress. After that, the procedure is specific to each browser; places like the various browser status trackers or bug trackers will be where implementation-specific discussion happens. That's kind of outside the scope of this repo though. |
Has there been any progress on this? We want to develop internal components that are project/framework agnostic. Ideally we want to be able to support Angular, React, and MVC patterns. The last one is the sticking point. Several of the components I want to build are basically form elements so I should be able to drop them in a form and submit with no additional code needed. Is there a workaround to support submitting the component's values with the enclosing form on submit? |
@PleasantD the only workarounds we've been able to find are to replicate the behaviour of form elements (which requires you to also to replicate Replicating form and input behaviour is robust, and allows you to keep shadow DOM encapsulation, but can work well when implemented correctly and edge-cases are tested. We've documented roughly how to do this here: https://skatejs.gitbooks.io/skatejs/content/docs/recipes/form-behaviour-and-the-shadow-dom.html. This can work with any web component library, not just Skate. The downfall here is that your custom Not using shadow DOM works well for leaf nodes. Luckily, most form elements are leaf nodes. However, it falls short when you want to use the custom element in a library that takes over control of You could try and use the |
We've made a concrete proposal three years ago in https://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0448.html |
Re: Form-associated non-custom elements,
|
Apologies if this has been discussed. I couldn't find them. In testing form-associated custom elements I ran into the following two cases:
|
I'll defer to @tkent-google as the real expert, but some quick notes while he's away for the weekend:
|
Making this work manually and matching the implicit submission behavior would require us to query for the default button as submitter, and submit its value too (via whatwg/html#4187 I guess).
Given the above, yes, it'd be more ideal if this is handled automatically with the same algorithm.
In my experience GitHub users rely on this behavior a lot, and always promptly report the bug when we break it. |
cc @sfdciuie who raised the issue about compound controls during the F2F meeting last week. I think @tkent-google explanation makes sense, we should be fine with something like that. |
Implicit submissionWith whatwg/html#4187, manual implicit submission code would be: let form = this.#internals.form;
// form.querySelector(':default') doesn't work due to 'form' content attribute.
for (let control of form.elements) {
if (control.matches(':default')) {
if (!control.matches(':disabled'))
form.requestSubmit(control);
return;
}
}
form.requestSubmit(); Introducing a flag like :defaultWe should be able to make a submit button with form-associated custom element. I just found a user agent needs to check if a form-associated custom element is a submit button or not to handle the AutofocusI proposed to move autofocus attribute to HTMLElement. whatwg/html#4563 |
First let met say that all of these things seem like they can be done on top of the current FACE (form-associated custom elements) pull request. That's a good sign :). So I think there are two issues with implicit submission:
This is about (1), from what I can tell. I think But I also wonder, it seems like you'd need to add code like that to an keydown (keypress? keyup?) handler, and filter for the Enter key, right? That seems a bit fragile since it's assuming the Enter key is correct, but that's just prevailing convention... Maybe the missing piece is some kind of "requestimplicitsubmit" event, which gets fired on the Enter key or similar? Or a custom element callback?? I also think there's room for making this easier by adding a In general I like the idea of people adding this manually, but doing it using platform-provided primitives that make it intuitive. So with all of my above it might be something like this.addEventListener("requestimplicitsubmit", () => {
const button = this.#internals.form.defaultButton;
if (!button.disabled) {
button.click();
}
}); To reiterate, I am happy with these pieces being done after the initial version of FACE.
This seems to start discussing (2). In particular I think I also wonder about how this relates to #738 (comment) about allowing you to manually toggle states like I've honestly never seen anyone use |
I also think so. We don't need incompatible changes against whatwg/html#4383 in order to resolve known issues. So, we, Chromium project, would like to start shipping process of both of event-based participation and form-associated custom element early next week. Does anyone still want to review these APIs? |
This is for WICG/webcomponents#187 Specification PR: whatwg/html#4383
This is for WICG/webcomponents#187. Specification PR: whatwg/html#4383.
Thanks everyone who accompanied us on this four-year journey!! On top of the feature that just got merged into the HTML spec, we have the following follow-up issues to make custom elements EVEN MORE powerful and on par with built-in elements:
|
I added a section to the proposal document for a list of follow-up issues. |
…ements', a=testonly Automatic update from web-platform-tests Add tests for form-associated custom elements This is for WICG/webcomponents#187. Specification PR: whatwg/html#4383. -- wp5At-commits: 3ccd79e32ced5ddab58f52e79f982d2ebfc7f98c wpt-pr: 15740
…ements', a=testonly Automatic update from web-platform-tests Add tests for form-associated custom elements This is for WICG/webcomponents#187. Specification PR: whatwg/html#4383. -- wp5At-commits: 3ccd79e32ced5ddab58f52e79f982d2ebfc7f98c wpt-pr: 15740
This is for WICG/webcomponents#187. Specification PR: whatwg/html#4383.
@tkent-google, are you still looking for feedback on the doc here? Just two notes:
|
I'm trying to build a form-associated web component and I've been able to get the example up and running.
or a number of callbacks like It will be interesting to see how this will get implemented from the MWC team: |
@dflorey Overriding |
Not sure if I understand correctly. In the given sample in the doc... ....and in all other examples that I've found it is also a bit weird that the validity will be set whenever the input changes as this is may be a very expensive operation. I'd also expect to have a but this seems not to work (quite yet)? It would be so cool to be able to implement a custom element that can be used as a drop-in replacement for native input fields or to add new exciting input controls, but right now I don't see a way to do so due to the issues above.
|
Title: [Custom]: Need callback for form submit data (bugzilla: 24603)
Migrated from: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603
comment: 0
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c0
Erik Arvidsson wrote on 2014-02-10 16:09:15 +0000.
Right now there is no way to have custom elements include data in form submissions. We should add another callback for this
I believe we need to add a callback that is called before the submit event.
Strawman:
document.registerElement('input', {
prototype: {
proto: HTMLElement.prototype,
beforeSubmitCallback: function() {
switch (this.type) {
case 'checkbox';
if (this.checked)
return this.value;
return undefined;
...
}
}
}
});
Basically, the contract is that the return value of the callback is used a the form value. If undefined is returned nothing is serialized.
This is of course a bit too simplistic but it might be enough to get started.
Things to keep in mind:
comment: 1
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c1
Boris Zbarsky wrote on 2014-02-10 16:20:44 +0000.
If is a subclass of , why can't it just set the .value to the thing it wants to submit?
If it's not a subclass of , you have other problems too, like form validation not knowing anything about it and so forth...
comment: 2
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c2
Erik Arvidsson wrote on 2014-02-10 16:30:48 +0000.
I agree it might be simpler to just subclass input but at some point we should explain how input is implemented too. That also includes explaining form validation and requestAutoComplete and probably tons of other things.
comment: 3
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c3
Boris Zbarsky wrote on 2014-02-10 16:37:53 +0000.
Sure. If we do that we need to make all the relevant algorithms robust to script randomly doing unexpected things. E.g. getting the value from an input can change the values of other inputs if it's done in arbitrary script....
The way input is implemented in practice, in ES terms, is that it has private slot (closure variable, weakmap entry, whatever) that stores a value string, and various form operations can retrieve that string without running any untrusted (from the point of view of the form) script in the process. Whatever setup we come up with for explaining input would be best if it preserved those invariants....
comment: 4
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c4
Anne wrote on 2014-02-12 18:16:49 +0000.
What about form association and label association? It seems you need hooks for those too.
comment: 5
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24603#c5
Dimitri Glazkov wrote on 2014-05-08 20:51:20 +0000.
There's another proposal here: http://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0448.html
The text was updated successfully, but these errors were encountered: