polymer-rails-forms 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +22 -0
- data/README.md +147 -0
- data/assets/rails-forms/gc-paper-decorator.html +18 -0
- data/assets/rails-forms/pikaday.css +173 -0
- data/assets/rails-forms/pikaday.js +920 -0
- data/assets/rails-forms/rails-form-helpers.html +744 -0
- data/assets/rails-forms/rails-form-validators.html +106 -0
- data/assets/rails-forms/rails-form.html +288 -0
- data/lib/polymer_rails_forms/railtie.rb +11 -0
- data/lib/tasks/install.rake +6 -0
- metadata +11 -1
@@ -0,0 +1,106 @@
|
|
1
|
+
<script>
|
2
|
+
var Validation = {
|
3
|
+
errors: {},
|
4
|
+
|
5
|
+
addValidation: function(type, input){
|
6
|
+
//TODO should validate everything
|
7
|
+
if (this.structure[this.key].required){
|
8
|
+
input.addEventListener("change", function(){
|
9
|
+
this.validate(this.structure[this.key].type, input);
|
10
|
+
}.bind(this), false)
|
11
|
+
} else if (!!this.structure[this.key].validates){
|
12
|
+
input.addEventListener("change", function(){
|
13
|
+
this[this.structure[this.key].validates](type, input)
|
14
|
+
}.bind(this), false)
|
15
|
+
}
|
16
|
+
},
|
17
|
+
|
18
|
+
invalidate: function(type, input, isInvalid){
|
19
|
+
var parent = this.findParent(input, 'gc-input-decorator'),
|
20
|
+
wrapper = this.findParent(input, '.input-wrapper'),
|
21
|
+
group = this.findParent(input, '.list-group'),
|
22
|
+
form = this.shadowRoot.querySelector("form");
|
23
|
+
|
24
|
+
if (!!parent) parent.isInvalid = isInvalid;
|
25
|
+
if (isInvalid){
|
26
|
+
this.errors[input.id] = "ERROR!!!!!!!!!"
|
27
|
+
if (!!wrapper) this.addClass(wrapper, "is-invalid");
|
28
|
+
if (!!group) this.addClass(group, "is-invalid");
|
29
|
+
} else {
|
30
|
+
delete this.errors[input.id];
|
31
|
+
if (!!wrapper) this.removeClass(wrapper, 'is-invalid');
|
32
|
+
if (!!group) this.removeClass(group, "is-invalid");
|
33
|
+
}
|
34
|
+
|
35
|
+
if (Object.keys(this.errors).length === 0){
|
36
|
+
if (!!form) this.removeClass(form, 'has-errors')
|
37
|
+
} else {
|
38
|
+
if (!!form) this.addClass(form, 'has-errors')
|
39
|
+
}
|
40
|
+
},
|
41
|
+
|
42
|
+
validate: function(type, input, required, invalidate){
|
43
|
+
required = required || input.required;
|
44
|
+
invalidate = invalidate || true;
|
45
|
+
|
46
|
+
var validators = {
|
47
|
+
string: function(){
|
48
|
+
return !(required && input.value.replace(/(^ *| *$)/g, "").length > 0);
|
49
|
+
},
|
50
|
+
|
51
|
+
email: function(){
|
52
|
+
return !(required && /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(input.value))
|
53
|
+
},
|
54
|
+
|
55
|
+
hidden: function(){
|
56
|
+
return false;
|
57
|
+
}.bind(this),
|
58
|
+
|
59
|
+
json: function(){
|
60
|
+
return false
|
61
|
+
}.bind(this),
|
62
|
+
|
63
|
+
password: function(){
|
64
|
+
return !(required && input.value.length > 0);
|
65
|
+
}.bind(this),
|
66
|
+
|
67
|
+
integer: function(){
|
68
|
+
console.log("checking integer", isNaN(input.value))
|
69
|
+
return !(required && !isNaN(input.value))
|
70
|
+
}.bind(this),
|
71
|
+
|
72
|
+
url: function(){
|
73
|
+
return !(required && /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/.test(input.value))
|
74
|
+
}.bind(this),
|
75
|
+
|
76
|
+
textarea: function(){
|
77
|
+
return !(required && input.value.replace(/(^ *| *$)/g, "").length > 0);
|
78
|
+
}.bind(this),
|
79
|
+
|
80
|
+
checkbox: function(){
|
81
|
+
return false
|
82
|
+
}.bind(this),
|
83
|
+
|
84
|
+
date: function(){
|
85
|
+
return false
|
86
|
+
}.bind(this),
|
87
|
+
|
88
|
+
location: function(){
|
89
|
+
return false
|
90
|
+
}.bind(this),
|
91
|
+
|
92
|
+
image: function(){
|
93
|
+
return !(required && input.value.length > 0)
|
94
|
+
}.bind(this)
|
95
|
+
}
|
96
|
+
|
97
|
+
var isInvalid = (!!validators[type] && validators[type]())
|
98
|
+
|
99
|
+
if (invalidate){
|
100
|
+
this.invalidate(type, input, isInvalid);
|
101
|
+
}
|
102
|
+
|
103
|
+
return isInvalid;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
</script>
|
@@ -0,0 +1,288 @@
|
|
1
|
+
<link rel="import" href="rails-form-helpers.html" >
|
2
|
+
<link rel="import" href="rails-form-validators.html" >
|
3
|
+
<link rel="import" href="gc-paper-decorator.html" >
|
4
|
+
<link rel="import" href="../paper-button/paper-button.html" >
|
5
|
+
<link rel="import" href="../core-icons/image-icons.html" >
|
6
|
+
<link rel="import" href="../core-ajax/core-xhr.html" >
|
7
|
+
|
8
|
+
<script src='pikaday.js'></script>
|
9
|
+
|
10
|
+
<polymer-element name="rails-form">
|
11
|
+
<template>
|
12
|
+
<link rel='stylesheet' href='pikaday.css'>
|
13
|
+
<style>
|
14
|
+
paper-button {
|
15
|
+
font-size: 14px;
|
16
|
+
}
|
17
|
+
|
18
|
+
paper-button core-icon {
|
19
|
+
margin-right: 5px;
|
20
|
+
color: #5bc0de;
|
21
|
+
}
|
22
|
+
|
23
|
+
#submit-button {
|
24
|
+
margin-top: 15px;
|
25
|
+
padding-left: 30px;
|
26
|
+
padding-right: 30px;
|
27
|
+
background-color: #5bc0de;
|
28
|
+
border-color: #46b8da;
|
29
|
+
color: white;
|
30
|
+
}
|
31
|
+
|
32
|
+
gc-input-decorator {
|
33
|
+
text-align: left !important;
|
34
|
+
}
|
35
|
+
|
36
|
+
gc-input-decorator .label {
|
37
|
+
text-align: left !important;
|
38
|
+
}
|
39
|
+
|
40
|
+
.btn-image-upload {
|
41
|
+
position: relative;
|
42
|
+
overflow: hidden;
|
43
|
+
width: 100%;
|
44
|
+
height: 59px;
|
45
|
+
display: table;
|
46
|
+
}
|
47
|
+
|
48
|
+
.btn-image-upload core-icon {
|
49
|
+
height: 105px;
|
50
|
+
width: 105px;
|
51
|
+
margin: 0 auto;
|
52
|
+
display: block;
|
53
|
+
color: #666;
|
54
|
+
}
|
55
|
+
|
56
|
+
.btn-image-upload input[type=file] {
|
57
|
+
position: absolute;
|
58
|
+
top: 0;
|
59
|
+
left: 0;
|
60
|
+
width: 100%;
|
61
|
+
height: 100%;
|
62
|
+
font-size: 999px;
|
63
|
+
text-align: right;
|
64
|
+
filter: alpha(opacity=0);
|
65
|
+
opacity: 0;
|
66
|
+
outline: none;
|
67
|
+
background: white;
|
68
|
+
cursor: inherit;
|
69
|
+
display: block;
|
70
|
+
}
|
71
|
+
|
72
|
+
.list-group {
|
73
|
+
width: 100%;
|
74
|
+
box-sizing: border-box;
|
75
|
+
display: block;
|
76
|
+
padding: 9px 0px 0px 10px;
|
77
|
+
font-size: 14px;
|
78
|
+
}
|
79
|
+
|
80
|
+
.list-group .list-item {
|
81
|
+
width: 100%;
|
82
|
+
}
|
83
|
+
|
84
|
+
.list-group .list-item .list-item-display {
|
85
|
+
border-bottom: solid 1px;
|
86
|
+
display: flex;
|
87
|
+
flex-direction: row;
|
88
|
+
}
|
89
|
+
|
90
|
+
.list-group .list-item .list-item-display div {
|
91
|
+
flex: 1;
|
92
|
+
cursor: pointer;
|
93
|
+
}
|
94
|
+
|
95
|
+
.list-wrapper {
|
96
|
+
overflow: auto;
|
97
|
+
font-size: 0px;
|
98
|
+
padding-top: 10px;
|
99
|
+
min-height: 55px;
|
100
|
+
}
|
101
|
+
|
102
|
+
.list-wrapper .list {
|
103
|
+
overflow: auto;
|
104
|
+
position: relative;
|
105
|
+
float: right;
|
106
|
+
box-sizing: border-box;
|
107
|
+
width: 72%;
|
108
|
+
max-height: 81px;
|
109
|
+
}
|
110
|
+
|
111
|
+
.list-wrapper h4 {
|
112
|
+
padding: 10px 15px;
|
113
|
+
float: left;
|
114
|
+
box-sizing: border-box;
|
115
|
+
width: 25%;
|
116
|
+
margin: 0;
|
117
|
+
font-weight: 500;
|
118
|
+
font-size: 14px;
|
119
|
+
}
|
120
|
+
|
121
|
+
.list-group .list-item {
|
122
|
+
display: block;
|
123
|
+
list-style-type: none;
|
124
|
+
margin: 0;
|
125
|
+
padding: 0 15px;
|
126
|
+
box-sizing: border-box;
|
127
|
+
}
|
128
|
+
|
129
|
+
.list-group .list-form {
|
130
|
+
display: none;
|
131
|
+
}
|
132
|
+
|
133
|
+
.list-group.focused .list-item, .list-group.is-invalid .list-item, .list-group.is-blank .list-item {
|
134
|
+
display: none;
|
135
|
+
}
|
136
|
+
|
137
|
+
.list-group.focused .list-form, .list-group.is-invalid .list-form, .list-group.is-blank .list-form {
|
138
|
+
display: block;
|
139
|
+
}
|
140
|
+
|
141
|
+
paper-checkbox input[type=checkbox] {
|
142
|
+
display: none;
|
143
|
+
}
|
144
|
+
|
145
|
+
</style>
|
146
|
+
<!-- TODO: structures should be arrays to preserve order -->
|
147
|
+
<form id="rails_form" _action="{{ action }}" method="{{ method }}" enctype="multipart/form-data">
|
148
|
+
<template bind="{{ data as data }}">
|
149
|
+
<template bind="{{ structure as structure }}" bind="{{ scope as scope }}" id="form-group">
|
150
|
+
<template repeat="{{ key in structure | getKeys }}">
|
151
|
+
<div class='{{ structure[key] | wrapperClass }} {{ key }} {{ structure[key] | isHidden }}'>
|
152
|
+
<template if="{{ structure[key] | isNest }}">
|
153
|
+
<template if="{{ structure[key].allowAdd }}">
|
154
|
+
<paper-button class='{{ key | scopeToClass }}' on-click="{{ addItem }}"><core-icon icon="add-circle-outline"></core-icon>{{ structure[key].label }}</paper-button>
|
155
|
+
</template>
|
156
|
+
<template if="{{ structure[key] | isMultiple }}">
|
157
|
+
<template if="{{ !structure[key].allowAdd }}">
|
158
|
+
<template repeat="{{ item in data | scopeNestData(key) | enumerate }}">
|
159
|
+
<template ref="form-group" bind="{{ structure[key].structure as structure }}" parentContext="{{ key | updateParentContext }}" scope="{{ scope | updateScope(key) | addIndex(item) }}" data="{{ data | scopeDataToIndex(item) }}"></template>
|
160
|
+
</template>
|
161
|
+
</template>
|
162
|
+
|
163
|
+
<template if='{{ structure[key].allowAdd }}'>
|
164
|
+
<template bind="{{ data as data }}">
|
165
|
+
<div class='list'>
|
166
|
+
<template repeat="{{ item in data | scopeNestData(key) | enumerate }}">
|
167
|
+
<div class='list-group {{ item | isEmpty }}'>
|
168
|
+
<div class='list-item {{ item | listItemClassName }}'>
|
169
|
+
{{ item | createListItem }}
|
170
|
+
</div>
|
171
|
+
<div class='list-form {{ item | listItemClassName }}'>
|
172
|
+
<template ref="form-group" bind="{{ structure[key].structure as structure }}" parentContext="{{ key | updateParentContext }}" scope="{{ scope | updateScope(key) | addIndex(item) }}" data="{{ data | scopeDataToIndex(item) }}"></template>
|
173
|
+
</div>
|
174
|
+
</div>
|
175
|
+
</template>
|
176
|
+
</div>
|
177
|
+
</template>
|
178
|
+
</template>
|
179
|
+
</template>
|
180
|
+
|
181
|
+
<template if="{{ structure[key] | isNotMultiple }}">
|
182
|
+
<template bind="{{ context as context }}">
|
183
|
+
<template ref="form-group" bind="{{ structure[key].structure as structure }}" parentContext="{{ key | updateParentContext }}" scope="{{ scope | updateScope(key) }}" data="{{ data | scopeNestData(key) }}"></template>
|
184
|
+
</template>
|
185
|
+
</template>
|
186
|
+
</template>
|
187
|
+
|
188
|
+
<template if="{{ structure[key] | isField }}">
|
189
|
+
<template bind="{{ data as data }}">
|
190
|
+
<div class="input {{ key | scopeToClass }}" scope="{{ data | scopeFieldData(key) }}">
|
191
|
+
{{ structure[key] | createInput }}
|
192
|
+
</div>
|
193
|
+
</template>
|
194
|
+
</template>
|
195
|
+
</div>
|
196
|
+
</template>
|
197
|
+
</template>
|
198
|
+
</template>
|
199
|
+
<div class='sumbit-button-wrapper'>
|
200
|
+
<paper-button id='submit-button' raised>{{ submitText }}</paper-button>
|
201
|
+
<template if="{{ xhr }}">
|
202
|
+
<core-xhr id='xhr'></core-xhr>
|
203
|
+
</template>
|
204
|
+
</div>
|
205
|
+
</form>
|
206
|
+
</template>
|
207
|
+
<script>
|
208
|
+
/*
|
209
|
+
Default Structure Item: {
|
210
|
+
type: "string",
|
211
|
+
label: "",
|
212
|
+
options: {
|
213
|
+
floatingLabel: true,
|
214
|
+
unscoped: false,
|
215
|
+
events: {}
|
216
|
+
},
|
217
|
+
attributes: {
|
218
|
+
|
219
|
+
}
|
220
|
+
}
|
221
|
+
*/
|
222
|
+
|
223
|
+
Polymer( Polymer.mixin ({
|
224
|
+
publish: {
|
225
|
+
scope: "",
|
226
|
+
action: "",
|
227
|
+
method: "POST",
|
228
|
+
structure: null,
|
229
|
+
data: null,
|
230
|
+
submitText: "Submit",
|
231
|
+
xhr: false,
|
232
|
+
onSubmit: null
|
233
|
+
},
|
234
|
+
|
235
|
+
parentContext: null,
|
236
|
+
parentStructure: null,
|
237
|
+
parentData: null,
|
238
|
+
|
239
|
+
toArray: function(str){
|
240
|
+
return [str];
|
241
|
+
},
|
242
|
+
|
243
|
+
created: function(){
|
244
|
+
this.structure = {};
|
245
|
+
this.data = {};
|
246
|
+
this.inputList = [];
|
247
|
+
},
|
248
|
+
|
249
|
+
handleXhrCallback: function(){
|
250
|
+
|
251
|
+
},
|
252
|
+
|
253
|
+
domReady: function(){
|
254
|
+
var form = this.shadowRoot.querySelector("form"),
|
255
|
+
button = this.shadowRoot.querySelector("paper-button");
|
256
|
+
|
257
|
+
button.addEventListener("click", function(e){
|
258
|
+
if (this.action !== null){
|
259
|
+
if (this.xhr){
|
260
|
+
this.$.xhr.request({ method: this.method, url: this.action, params: this.data, callback: this.handleXhrCallback })
|
261
|
+
} else {
|
262
|
+
form.submit();
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}.bind(this), false)
|
266
|
+
|
267
|
+
this.appendInputs();
|
268
|
+
|
269
|
+
var inputObserver = new ArrayObserver(this.inputList);
|
270
|
+
inputObserver.open(function(splices){
|
271
|
+
this.appendInputs();
|
272
|
+
}.bind(this))
|
273
|
+
|
274
|
+
form.addEventListener("change", function(e){
|
275
|
+
var group = this.findParent(e.target, ".list-group")
|
276
|
+
if (!!group){
|
277
|
+
this.checkForBlank(group);
|
278
|
+
}
|
279
|
+
}.bind(this), true)
|
280
|
+
|
281
|
+
},
|
282
|
+
|
283
|
+
get getData() {
|
284
|
+
return this.data;
|
285
|
+
}
|
286
|
+
}, FormHelpers, Validation));
|
287
|
+
</script>
|
288
|
+
</polymer-element>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymer-rails-forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Weber
|
@@ -31,7 +31,17 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- assets/rails-forms/gc-paper-decorator.html
|
37
|
+
- assets/rails-forms/pikaday.css
|
38
|
+
- assets/rails-forms/pikaday.js
|
39
|
+
- assets/rails-forms/rails-form-helpers.html
|
40
|
+
- assets/rails-forms/rails-form-validators.html
|
41
|
+
- assets/rails-forms/rails-form.html
|
34
42
|
- lib/polymer-rails-forms.rb
|
43
|
+
- lib/polymer_rails_forms/railtie.rb
|
44
|
+
- lib/tasks/install.rake
|
35
45
|
homepage: https://github.com/gearcommons/polymer-rails-forms
|
36
46
|
licenses:
|
37
47
|
- MIT
|