way.js ====== [](https://gitter.im/gwendall/way.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Simple, lightweight, persistent, framework-agnostic two-way databinding Javascript library. With no to little JS code to write. And no dependencies. [Demo](https://gwendall.github.io/way) [Codepen](http://codepen.io/anon/pen/rihBs) [jsFiddle](http://jsfiddle.net/gwendall/s5zzc84m/) Buy us coffee: [Gittip](https://www.gittip.com/gwendall) Follow us on Twitter: [@way_js](https://twitter.com/way_js) The following documentation is also available in [Chinese](https://github.com/gwendall/way.js/blob/master/docs/zh-CN.md) (credits: [@wuyunjiang](https://github.com/wuyunjiang)). ## Quick start ## Declare an HTML element with some tags. ```html
Name: ``` Boom. Now every change in the form will be stored in-memory. The bound span's html will be changed on the fly. And the bound data will be persistent, meaning your HTML will be populated with your data on page reloads. Enough talk, [see it in action](https://gwendall.github.io/way). ## Installation ## **[Step 1]** Include the library to your page. **1.a. via NPM** ```html npm install way-js ``` then ```javascript import 'way-js'; ``` **1.b. or** ```html ``` **[Step 2]** There is no step 2. You are good to go. ## Options ## Options can be passed via data attributes or JavaScript. For data attributes, append the option name to way-, as in way-data="". Set these options to the elements that have to be bound. Name | Type | Default | Description ----|------|---- | ---- data | string | null | Allows to define the dot separated path where the data will be stored. Can include arrays. When used on a form, a json variable made of all the included inputs with a [name] attribute will be created and stored in the specified storage. Pass the "\_\_all\_\_" path to access all way.js' data. default | string | null | A link to a default data to set on an element, in case there is no bound value. persistent | boolean | true | Allows to store the data to localStorage everytime the bound data changes. readonly | boolean | false | Prevents the element changes from resetting the bound value. writeonly | Boolean | false | Prevents the element from getting changed when the bound value changes. json | boolean | false | Returns pretty-printed json data to its DOM element. html | boolean | false | Declares whether the data attributed to an element should be parsed as HTML or not. pick | array | null | A comma separated list of values to pick (in forms only) to sync with the storage. By default, all form inputs are synced. omit | array | null | A comma separated list of values (in forms only) to not sync with the storage. By default, no form input is omitted. Some examples: ```html