@f/get-value

1.0.1 • Public • Published

get-value

Build status Git tag NPM version Code style

Retrieve the value of a form field

Installation

$ npm install @f/get-value

Usage

It gets the value of a form field and normalizes it a bit:

  • Checkboxes/Radio-buttons return true if they are checked and don't have an explicit value set, and the value if they do. They return false if they are unchecked.
  • Select will return the value of the option that is selected.
  • ...Everything else just returns el.value.
var controls = require('@f/form-controls')
var getValue = require('@f/get-value')
var brackets = require('@f/brackets')
var reduce = require('@f/reduce')

function serialize (form) {
  return reduce(function (acc, ctrl) {
    return brackets(acc, ctrl.name, getValue(ctrl))
  }, {}, controls(form))
}

API

getValue(element)

  • element - The element who's value you want to get

Returns: The value of the element, normalized according to the rules listed above.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @f/get-value

Weekly Downloads

53

Version

1.0.1

License

MIT

Last publish

Collaborators

  • f