Contents
Intro
Form Data
Gotcha's
Examples
Summary
Intro
I have a love, but sometimes hate, relationship with HTML Forms....
For further actions, you may consider blocking this person and/or reporting abuse
you can also try Object.fromEntries([...formData])
In fact, you don't event need the [...]. You can just do
Object.fromEntries(formData):)Oh, nice that's even simpler! If you don't have the 'inputs with same name' gotcha.
Right. Do you have examples of inputs with the same name? I can only think of radio inputs, but in that case, it will only take the one that was selected. You probably know some other use-cases though.
It probably not that common but if you want a list of things a user could check.
For example, if there was a list of languages as checkbox inputs, they could check each one they knew and the output of the Full Example would give you an Array of the languages the user knows.
If you open the Interactive Example in JSFiddle you can see the console output for this :)
I have a question; does this make sense if you use
name="lang[js]"andname="lang[py]"?Hi Jordan, nice post. If you use Reactjs you may be also interested on iusehooks.github.io/usetheform/ . It handles forms state in react and much more.
Thank you for the comment. :)
Is this a library you've written?
Hi, yes I did write it :)