Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FormData constructor to accept array or object too #202

Open
jimmywarting opened this issue Apr 18, 2018 · 4 comments
Open

Allow FormData constructor to accept array or object too #202

jimmywarting opened this issue Apr 18, 2018 · 4 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: formdata

Comments

@jimmywarting
Copy link

jimmywarting commented Apr 18, 2018

Like the URLSearchParams allow the FormData constructor able to accept a iterable array or object
instead of having to manually append everything

Current way of solving things:

var data = [ ['foo', 'bar'] ]
var data = { foo: 'bar' }

var fd = new FormData()

for (let [key, val] of new URLSearchParams(data)) {
  fd.append(key, val)
}

// or one-liner 
new URLSearchParams(data).forEach(args => fd.append(...args))

(this don't work for files/blobs)

Suggested way

var data = [ ['foo', 'bar'] ]
var data = { foo: 'bar' }

var fd = new FormData(data)
@annevk annevk added needs implementer interest Moving the issue forward requires implementers to express interest addition/proposal New features or enhancements labels Apr 18, 2018
@travisleithead
Copy link
Member

note var data = [ 'foo', 'bar' ]; might not work, it'd need to be var data = [ [ 'foo', 'bar'] ]; Otherwise this looks like a good idea.

@jimmywarting
Copy link
Author

jimmywarting commented Sep 25, 2018

That is probably what i meant. updated my examples

@TheLarkInn
Copy link

@travisleithead Almost makes more sense to me to use Map() or Set() instead of plan Array or Object literals.

Another facet to consider.

@silverwind
Copy link

silverwind commented Mar 1, 2024

+1, this would be very nice to have. I'd definitely use the object form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: formdata
Development

No branches or pull requests

7 participants
@silverwind @jimmywarting @annevk @travisleithead @TheLarkInn and others