scala-js/scala-js-dom

It looks we are missing some methods from the FormData class

G-yhlee opened this issue · 2 comments

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 {

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 is updated and merged at #800

Thanks all !