@f/get-value
v1.0.1
Published
Retrieve the value of a form field
Downloads
557
Readme
get-value
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 returnfalse
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