I want to two-way databind the field values of an iron-form
to a Firebase node (representing user-defined settings, for example).
<dom-module id="my-settings">
<template>
<firebase-document location="[[firebaseUrl]]"
data="{{form}}">
</firebase-document>
<form is="iron-form" id="form">
<paper-checkbox id="history"
name="history"
on-change="_computeForm"
>Save history
</paper-checkbox>
<!-- ... -->
<!-- All types of form fields go here -->
<!-- ... -->
</form>
</template>
<script>
(function() {
Polymer({
is: 'my-settings',
_computeForm: function() {
this.form = this.$.form.serialize();
}
});
})();
</script>
</dom-module>
This form needs to:
- persist its state to firebase upon changes (i.e., first-way binding — client to firebase) and
- set form fields to their saved values upon loading (i.e., second-way binding — firebase to client — completing the two-way binding).
Questions
Please provide the best practice solution for accomplishing this.
Is it possible to bind the entire form (declaratively?) and avoid having to imperatively set each form field value independently upon load?
I encourage pseudocode or concepts that point me in the right direction.