whatwg / xhr

XMLHttpRequest Standard
https://xhr.spec.whatwg.org/
Other
314 stars 131 forks source link

FormData & submitter[formaction] #381

Open Lcfvs opened 1 year ago

Lcfvs commented 1 year ago

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?

annevk commented 1 year ago

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?

Lcfvs commented 1 year ago

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.

annevk commented 1 year ago

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.

Lcfvs commented 1 year ago

Ok, ok :)

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

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.

annevk commented 1 year ago

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!

Lcfvs commented 1 year ago

Thanks a lot for that shared curiosity :)