-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-fire.html
81 lines (71 loc) · 1.91 KB
/
form-fire.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--
@license
Copyright (c) 2016 Convoo All Rights Reserved.
Use of this source code is governed by a MIT license that can be found in the
LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../polymerfire/firebase-document.html">
<!--
`form-fire`
A collection of elements for inserting text and image data to firebase database
@demo demo/index.html
-->
<dom-module id="form-fire">
<template>
<firebase-document
app-name="[[appName]]"
id="form"
path="[[path]]"
data="{{data}}">
</firebase-document>
<style>
:host {
display: block;
}
</style>
<content></content>
</template>
<script>
Polymer({
is: 'form-fire',
properties: {
path: {
type: String,
},
data:{
type: Object,
observer: '_setValues',
},
},
attached: function() {
this.nodes = Polymer.dom(this).children;
for (var i = 0; i < this.nodes.length; i++) {
if(this.nodes[i].type == 'submit') {
this.nodes[i].addEventListener('click', function (event) {
this.submit();
}.bind(this))
}
}
},
submit: function(){
this.nodes = Polymer.dom(this).children;
var input = new Object;
for (var i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].value && this.nodes[i].name){
input[this.nodes[i].name] = this.nodes[i].value;
}
}
this.$.form.ref.update(input);
},
_setValues: function(){
this.nodes = Polymer.dom(this).children;
for (var i = 0; i < this.nodes.length; i++) {
if(this.data[this.nodes[i].name]){
this.nodes[i].value = this.data[this.nodes[i].name]
}
}
},
});
</script>
</dom-module>