[webcomponents] [Custom]: Need callback for form submit data (bugzilla: 24603) (#187)

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.

\<form\>
  \<my-custom-input name="abc">\</my-custom-input\>
\</form\>

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:

- Radio buttons need to check outside itself
- input[type=file]. Return Blob|File|data url?
- input[multiple]. Array of values?

----

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 \<my-custom-input\> is a subclass of \<input\>, why can't it just set the .value to the thing it wants to submit?

If it's not a subclass of \<my-custom-input\>, 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

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/187

Received on Monday, 6 July 2015 07:39:31 UTC