Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fio

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fio

Get/set data in form fields with consistent type coercion and validation

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

fio

"fio" (form IO) is a set of utilities for getting/setting data in HTML input and select form fields more consistently type coercion and validation.

It follows these conventions:

  • Disabled fields are ignored when getting values, but will be set if a value exists for it
  • Only checkboxes and radio buttons that checked are returned
  • Selectors pointing to inputs will be treated as a multi-value fields and will return an array on get (as well as expect an array when set). This of course excludes radio buttons due to the constraint mentioned above.
  • Checkbox and radio buttons are set via their value
  • Values are coerced based on the data-type attribute if one is present and falls back to the type attribute
  • Empty values are coerced to null

Requirements

  • jQuery
  • Datejs (only if you are doing date parsing)

Download

Install

AMD
<script src="require.js"></script>
<script>require(['fio'], function(fio) { ... })</script>
Traditional
<script src="jquery.js"></script>
<script src="fio.js"></script>

API

fio.get(selector)

Gets the input value given the selector.

fio.set(selector, value)

Sets the input value for the selector.

fio.coerce(value, type)

Coerces some value for the given type. This is generally performed after getInputValue is used.

fio.check(value, type)

Validates a value is of the given type. Returns a boolean denoting the result.

Examples

Checkboxes:
<input type=checkbox name=cbox1 value=foo checked>
<input type=checkbox name=cbox1 value=bar>
<input type=checkbox name=cbox1 value=baz checked>
fio.get('[name=cbox1]'); // ['foo', 'baz']
Multiple Inputs
<input name=range1 value=1>
<input name=range1 value=2>
fio.get('[name=range1]'); // [1, 2]
Disable Input
<input name=range2 value=1>
<input name=range2 value=2 disabled>
fio.get('[name=range2]'); // 1

Keywords

FAQs

Package last updated on 17 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc