ampersand-checkbox-view
A view module for intelligently rendering and validating checkbox input. Works well with ampersand-form-view.
It does the following:
- Automatically shows/hides error message based required.
- Will only show error message checkbox is required and:
- trying to submit form and it's not checked.
- it has ever been checked and now isn't.
Depdent on two micro-libs, so works well with ampersand apps, backbone apps or anything else, really.
Part of the Ampersand.js toolkit for building clientside applications.
install
npm install ampersand-checkbox-view
example
var CheckboxView = require('ampersand-checkbox-view');
var field = new CheckboxView({
name: 'client_name',
template:
label: 'App Name',
value: true,
el: document.getElementByID('field'),
required: true,
validClass: 'input-valid',
type: 'text',
invalidClass: 'input-invalid',
requiredMessage: 'This box must be checked.',
parent: someViewInstance
});
document.querySelector('form').appendChild(field.el);
browser support
credits
Created by @HenrikJoreteg.
license
MIT