xhr icon indicating copy to clipboard operation
xhr copied to clipboard

FormData & submitter[formaction]

Open Lcfvs opened this issue 1 year ago • 6 comments

Hi,

Is it possible to improve the behavior spec about the new FormData(form, submitter), to simply support something like this, please?

Using a submitter like:

<button formaction="..." formenctype="multipart/form-data" formmethod="post" type="submit" name="name" value="value">text</button>
new FormData(undefined, submitter) // actually, FormData (0)

Imho, if the button is a standalone submitter, there is no reason to be owned by a form to use it as a FormData submitter.

Any thoughts about that idea?

Lcfvs avatar Sep 15 '23 07:09 Lcfvs

It seems this would be rather magical as https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set has an early return for an empty form. I guess we would have to pretend that the form contains the submitter in this case.

Perhaps you could elaborate on when this kind of thing has come up?

annevk avatar Sep 15 '23 10:09 annevk

Sorry, my bad... Honestly, I just discovered that requirement: "Does nothing if there is no form owner."

Then a submitter can't be standalone, invalidating my question.

I'm self-asking why that required dependency but don't want to annoy you longer with that.

Thanks anyway.

Lcfvs avatar Sep 15 '23 11:09 Lcfvs

You're not annoying me! Just curious. I think the dependency is there because we get the fields from the form and then the submitter identifies the field that is the submitter. As I suggested above we could potentially invert some of that, but would need a compelling use case and some signal of web developer demand.

annevk avatar Sep 15 '23 12:09 annevk

Ok, ok :)

In fact, actually, the idea behind to use them, as standalone, is to replace some anchors by some button[formaction]...

  • to avoid any risks related to the page preview feature of some browsers (AFAIK like planned for Chrome)
  • to have a "dynamic" variable sent to the server, based on the attributes (name & value), without to have something to manage it, even in GET/POST and/or in AJAX or not

And, really, I'm not convinced about the need of an extra form, trailing somewhere in the page to be able to send one of these buttons requests... moreover since it requires an id, "polluting" the globalThis for that... where these buttons can have anything we need to perform the requests, alone.

Lcfvs avatar Sep 15 '23 12:09 Lcfvs

Alright, let's reopen this to see if more people hit this or if we find it to be a common library pattern or Stack Overflow question. Thanks!

annevk avatar Sep 15 '23 13:09 annevk

Thanks a lot for that shared curiosity :)

Lcfvs avatar Sep 15 '23 13:09 Lcfvs