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

FormData has() should include a second param for matching the value like URLSearchParams #392

Open
knowler opened this issue Nov 2, 2024 · 1 comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: formdata

Comments

@knowler
Copy link

knowler commented Nov 2, 2024

What problem are you trying to solve?

FormData objects can have multiple entries with the same key. The FormData has() method is useful checking a key exists in the object, however, when there are multiple keys with the same name it is less useful since in that case you don’t just care about the key, but also if a key and value are present.

What solutions exist today?

Today, it’s not terribly difficult to achieve this, but it does require getting all of the values as an array and then using Array methods to check if the value exists.

For example, where formData is a FormData object:

formData.getAll("fruit").includes("tomato");

How would you solve it?

The URLSearchParams has() method supports a second parameter for matching the value of the named param. For example, where searchParams is a URLSearchParams object:

searchParams.has("fruit", "tomato"); // returns a boolean if there’s a matching key with the specified value

This would be useful for FormData as well. So, again where formData is a FormData object and the has() method supports a second parameter for matching the name and value in the object:

formData.has("fruit", "tomato"); // returns a boolean if there’s a matching key with the specified value

Additionally, this would help authors as there would be increased API parity between FormData and URLSearchParams.

Anything else?

No response

@knowler knowler added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Nov 2, 2024
@annevk
Copy link
Member

annevk commented Nov 3, 2024

Seems reasonable, we should do the same for delete() as per whatwg/url@bfb9157.

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

2 participants