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

It looks we are missing some methods from the FormData class #798

Closed
G-yhlee opened this issue Jul 23, 2023 · 2 comments
Closed

It looks we are missing some methods from the FormData class #798

G-yhlee opened this issue Jul 23, 2023 · 2 comments
Labels

Comments

@G-yhlee
Copy link
Contributor

G-yhlee commented Jul 23, 2023

In js world ,

FormData Object have append and get method,

// example ) https://developer.mozilla.org/en-US/docs/Web/API/FormData/get
const formData = new FormData(event.target);
formData.append("username", "Chris");
formData.append("username", "Bob");
formData.get("username"); // Returns "Chris"

but scalajs FormData class has only append method,
we need to add get method like this...

// current  
formData.asInstanceOf[js.Dynamic].get("username").asInstanceOf[String]

// todo :  add get method
formData.get("username")

ref.

class FormData(form: HTMLFormElement = js.native) extends js.Object {

@faveoled
Copy link
Contributor

Here's the variant generated by AI (untested):

@js.native
@JSGlobal
class FormData(form: HTMLFormElement = js.native) extends js.Object {

  /** Appends a key/value pair to the FormData object. */
  def append(name: String, value: String | Blob, blobName: String = js.native): Unit = js.native

  /** Deletes a key/value pair from the FormData object. */
  def delete(name: String): Unit = js.native

  /** Returns an iterator that iterates through all key/value pairs contained in the FormData. */
  def entries(): Iterator[js.Tuple2[String, String | Blob]] = js.native

  /** Returns the first value associated with a given key from within a FormData object. */
  def get(name: String): String | Blob = js.native

  /** Returns an array of all the values associated with a given key from within a FormData. */
  def getAll(name: String): js.Array[String | Blob] = js.native

  /** Returns whether a FormData object contains a certain key. */
  def has(name: String): Boolean = js.native

  /** Returns an iterator iterates through all keys of the key/value pairs contained in the FormData. */
  def keys(): Iterator[String] = js.native

  /** Sets a new value for an existing key inside a FormData object, or adds the key/value if it does not already exist. */
  def set(name: String, value: String | Blob, blobName: String = js.native): Unit = js.native

  /** Returns an iterator that iterates through all values contained in the FormData. */
  def values(): Iterator[String | Blob] = js.native
}

This was referenced Jul 26, 2023
@G-yhlee
Copy link
Contributor Author

G-yhlee commented Aug 1, 2023

This is updated and merged at #800

Thanks all !

@G-yhlee G-yhlee closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants