Form Input
Renders form inputs and form input groups with feedback.
Can be used in the browser or with npm.
npm install form-input
var formInput = ;
Input
Set Attributes, Set Value to undefined for an attribute without a value.
formInputinput type:'text' name: 'foo' 'data-foo': undefined ;
If given a value and "name" attribute, and the value is an object with a key of the same value as the "name" attribute, the "name" value will be used.
formInputinput type:'text' name: 'foo' value: foo: 'a' bar: 'b' ;
If passed a value attribute with an array of values, the input will be repeated for each value.
formInputinput type:'checkbox' name: 'foo[]' value: 'a' 'b';
If passed a array value attribute and a checked attribute, the matching checked values will be given a "checked" attribute.
formInputinput type: 'radio' value: 'a' 'b' checked: 'b';
If passed a array value attribute and an array checked attribute, the matching checked values will be given a "checked" attribute.
formInputinput type: 'checkbox' value: 'a' 'b' 'c' checked: 'a' 'b';
If passed a value attribute that is an array of objects, the input will be wrapped in a label attribute which is given a class name of "[type]-inline".
formInputinput type:'checkbox' name: 'foo[]' value: 'a' 'b';
foo bar
Select
select
follows simmilar logic to input
regarding the interaction of name and
value attributes.
formInput
bar foo
Textarea
textarea
follows simmilar logic to input
regarding the interaction of name
and value attributes.
formInput
bar
Feedback
feedback
may be used to render error or success messages next to form inputs.
formInput
foo
Feedback may be passed an array of strings that will be rendered with an unordered list.
formInput
foo bar
If Feedback is passed an object and name parameter it will pluck the appropriate name from the value object.
formInput
baz
If the object does contain the named value, feedback will return an empty string.
//returns empty stringformInput
Group
Groups labels, inputs and feedback in an html structure.
Group can take input
, select
, textarea
, and feedback
properties which will
behave the same as their counterpart methods documented above.
The name attribute can be pulled to the top level of the configuration, and will be used by input and feedback as shown below.
formInput
bar c
An example using a select
input
formInput
bar A B
Custom open and close tags
Most of the closing an opening tags can be overriden either globally
var formInput = groupOpen: '<group>' groupClose: '</group>';
Or when calling the feedback or group methods
formInput;
Here is an example that overrides all available open and close tags.
formInput;
foo bar