Edit this page

up.Params up.Params.fromForm(form)
Class method

This feature is experimental. It may be changed or removed in a future version.

Constructs a new up.Params instance from the given <form>.

The returned params may be passed as { params } option to up.request() or up.replace().

The constructed up.Params will include exactly those form values that would be included in a regular form submission. In particular:

  • All <input> types are suppported
  • Field values are usually strings, but an <input type="file"> will produce File values.
  • An <input type="radio"> or <input type="checkbox"> will only be added if they are [checked].
  • An <select> will only be added if at least one value is [checked].
  • If passed a <select multiple> or <input type="file" multiple>, all selected values are added. If passed a <select multiple>, all selected values are added.
  • Fields that are [disabled] are ignored
  • Fields without a [name] attribute are ignored.

Example

Given this HTML form:

<form>
  <input type="text" name="email" value="foo@bar.com">
  <input type="password" name="pass" value="secret">
</form>

This would serialize the form into an array representation:

let params = up.Params.fromForm('input[name=email]')
let email = params.get('email') // email is now 'foo@bar.com'
let pass = params.get('pass') // pass is now 'secret'

Parameters

form Element

A <form> element.

Return value

A new up.Params instance with values from the given form.