@f/get-value

Retrieve the value of a form field

Stats

StarsIssuesVersionUpdatedCreatedSize
@f/get-value
211.0.15 years ago6 years agoMinified + gzip package size for @f/get-value in KB

Readme

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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.