willowtreeapps/marionette.formview — pull request #2 by tlegard (2014-10-10 20:05:51+00:00)
Title: Implement persistable option in Mariontte FormView

By setting the persistsData property of a Marionette FormView to true, it will enable the storage and recovery of fields using sessionStorage, based on the className of the FormView.

In order to persist a field add the persist: true attribute.

```
var SignUpForm = Marionette.FormView.extend({
initialize: function (...) {....},
persistsData: true,
className: 'get-started-form',
data: { lastName: 'Legard' }.
fields: {
firstName: {
el: '#getting-started-firstname',
persist: true
},
lastName: {
el: '#getting-started-lastname',
persist: true
}
}
....
});
````
This will persist the FirstName field through page refresh until the browser window is closed, or explicitly removed by calling window.sessionStorage.removeItem('get-started-form') or by calling window.sessionStorage.clear()

Data explicitly passed in the this.data hash, will not be overridden. In the example, when the user refreshes, the last name will always render as 'Legard'