ampersand-checkbox-view
Lead Maintainer: Michael Garvin
overview
A view module for intelligently rendering and validating checkbox input. Works well with ampersand-form-view.
ampersand-checkbox-view extends ampersand-view, so you may further .extend({...})
it to your desire.
It does the following:
- Automatically shows/hides error message based on if the field is
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.
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',
invalidClass: 'input-invalid',
requiredMessage: 'This box must be checked.',
parent: someViewInstance,
beforeSubmit: function() { console.log('ampersand-checkbox-view rocks!'); }
});
document.querySelector('form').appendChild(field.el);
api
properties
Commonly accessed properties listed below. See the initialize()
function for additional properties available.
valid
(boolean)value
(boolean)startingValue
(boolean) - this is coerced from any initail value
provided during construction
functions
new CheckboxView()
- constructor
- see the example for constructor options
clear()
- sugar for
view.setValue(false);
reset()
- sugar for
view.setValue(this.startingValue);
setValue([boolean])
- sets the value of the view. the view will always maintain a value of type
boolean
.
changelog
- 5.0.0
- 4.1.0
- Remove
domify
and using ampersand-view renderWithTemplate
- 4.0.0
- Bump to ampersand-view 8.x
- 3.0.0
- Extend ampersand-view. Add support
autoRender
, clear
, reset
credits
Created by @HenrikJoreteg.
license
MIT