Two way data binding for HTML input elements. No setup required.
Click here for a demo.
meteor add nov1n:reactive-bind
Add data-binding='foo' to an input element to bind it to a Session variable named 'foo'.
<input type='text' data-binding='exampleVariable'/>
Binds the Session variable 'exampleVariable' to the input element in the DOM. Any changes to the text field will be reflected by the Session variable and vice versa.
<input type='text' data-binding='exampleVariable2'/>
The value stored in the Session variable is the text as String.
<input type='password' data-binding='exampleVariable3'/>
The value stored in the Session variable is the text as String.
<input type='number' data-binding='exampleVariable4'/>
The value stored in the Session variable is number as Number.
<textarea name='area' data-binding='exampleVariable5'></textarea>
The value stored in the Session variable is the text as tring.
<input type='radio' name='color' value='Red' data-binding='exampleVariable6'/> Red
<input type='radio' name='color' value='Blue' data-binding='exampleVariable6'/> Blue
<input type='radio' name='color' value='Green' data-binding='exampleVariable6'/> Green
The value stored in the Session variable is the input value as String.
<input type='date' data-binding='exampleVariable7'/>
The value stored in the Session variable is a Date object.
<input type='checkbox' name='vehicle' value='Bike' data-binding='exampleVariable8'/> Bike
<input type='checkbox' name='vehicle' value='Car' data-binding='exampleVariable8'/> Car
<input type='checkbox' name='vehicle' value='Plane' data-binding='exampleVariable8'/> Plane
The value stored in the Session variable is the input value as String. When more than one checkbox is checked, it becomes an array of Strings.
<input type='range' data-binding='exampleVariable9'/>
The value stored in the Session variable is the text as Number.
<input type='color' data-binding='exampleVariable10'/>
The value stored in the Session variable is the color as hex triplet String (e.g. '#FFFFFF').
The code is licensed under the MIT License (see LICENSE file).