ampersand-array-input-view
Lead Maintainer: Michael Garvin
overview
A view module for intelligently rendering and validating inputs that should produce an array of values. Works well with ampersand-form-view.
It does the following:
- Automatically shows/hides error messages based on tests
- Exposes control for adding more input fields.
- Exposes control removing all but required number of input fields.
- Will not show error messages pre-submit or it's never had a valid value. This lets people tab-through a form without triggering a bunch of error message.
- Live-validates to always report if in valid state, but only shows messages when sane to do so.
install
npm install ampersand-array-input-view
example
The only required attribute is a name. Everything else is optional.
var InputView = require('ampersand-array-input-view');
var field = new InputView({
name: 'client_name',
template:
fieldTemplate
label: 'App Name',
placeholder: 'My Awesome App',
value: ['hello'],
el: document.getElementByID('field'),
minLength: 0,
maxLength: 10,
validClass: 'input-valid',
type: 'text',
invalidClass: 'input-invalid',
requiredMessage: 'This field is required.',
tests: [
function (val) {
if (val.length < 5) return "Must be 5+ characters.";
}
],
parent: someViewInstance
});
document.querySelector('form').appendChild(field.el);
credits
Created by @HenrikJoreteg.
changelog
- 5.0.0 - update &-input-view dependency to 5.0.0
- 4.0.0 - bump major versions of most dependencies
license
MIT