-
Notifications
You must be signed in to change notification settings - Fork 2
/
t-input.html
287 lines (239 loc) · 7.14 KB
/
t-input.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<link rel="import" href="../polymer/polymer.html" />
<link rel="import" href="t-master-input.html" />
<link rel="import" href="t-textarea.html" />
<!--
`<t-input>` is a single-line text field with Material Design styling.
<t-input label="Input label"></t-input>
It may include an optional error message or character counter.
<t-input error-message="Invalid input!" label="Input label"></t-input>
<t-input char-counter label="Input label"></t-input>
For textarea pass multi-line as attribute
<t-input multi-line label="Textarea label"></t-input>
### Validation
Currently only `required` and `maxlength` validation is supported on textarea.
See `Polymer.PaperInputBehavior` for more API docs.
### Styling
See `Polymer.PaperInputContainer` for a list of custom properties used to
style this element.
-->
<dom-module id="t-input">
<template>
<style>
:host , #input{
display: block;
outline: none;
}
</style>
<template is="dom-if" if="[[!multiLine]]">
<t-master-input id="input" label="{{label}}" type="{{type}}" min="{{min}}" max="{{max}}" validate-on-blur="{{validateOnBlur}}" auto-validate$="{{autoValidate}}" disabled$="{{disabled}}" no-label-float$="{{noLabelFloat}}" char-counter$="{{charCounter}}" maxlength="{{maxLength}}" pattern="{{pattern}}" error-message="{{errorMessage}}" prevent-invalid-input$="{{preventInvalidInput}}" required$="{{required}}" value="{{value}}" on-value-change="_invalid" autocapitalize$="[[autocapitalize]]" autocorrect$="[[autocorrect]]" autocomplete$="[[autocomplete]]"></t-master-input>
</template>
<template is="dom-if" if="[[multiLine]]">
<t-textarea id="input" label="{{label}}" disabled$="{{disabled}}" validate-on-blur="{{validateOnBlur}}" no-label-float$="{{noLabelFloat}}" char-counter$="{{charCounter}}" maxlength="{{maxLength}}" value="{{value}}" error-message="{{errorMessage}}" rows$="{{rows}}" max-rows$="{{maxRows}}" required$="{{required}}" ></t-textarea>
</template>
</template>
</dom-module>
<script>
Polymer({
is: "t-input",
properties:{
/**
* Name property
*/
name: {
type: String,
value: '',
reflectToAttribute: true
},
/**
* The label for this input. Bind this to `<paper-input-container>`'s `label` property.
*/
label: {
type:String,
value:"Untitled Input Field",
reflectToAttribute: true
},
/**
* The type of the input. The supported types are `text`, `number` and `password`. Bind this
* to the `<input is="iron-input">`'s `type` property.
*/
type: {
type:String,
reflectToAttribute: true
},
/**
* A pattern to validate the `input` with. Bind this to the `<input is="iron-input">`'s
* `pattern` property.
*/
pattern: {
type:String,
reflectToAttribute: true
},
/**
* Set to true to show a character counter.
*/
charCounter: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* Set to true to validate on blur
*/
validateOnBlur: {
type: Boolean,
value: true
},
/**
* Set to true to prevent the user from entering invalid input. Bind this to the
* `<input is="iron-input">`'s `preventInvalidInput` property.
*/
preventInvalidInput:{
type: Boolean
},
/**
* The error message to display when the input is invalid. Bind this to the
* `<paper-input-error>`'s content, if using.
*/
errorMessage: {
type:String,
value:'required',
reflectToAttribute: true
},
/**
* Set to true to disable the floating label. Bind this to the `<paper-input-container>`'s
* `noLabelFloat` property.
*/
noLabelFloat: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* The maximum length of the input value. Bind this to the `<input is="iron-input">`'s
* `maxlength` property.
*/
maxLength: {
type:Number,
reflectToAttribute: true
},
/**
* The minimum (numeric or date-time) input value.
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `min` property.
*/
min: {
type: String
},
/**
* The maximum (numeric or date-time) input value.
* Can be a String (e.g. `"2000-1-1"`) or a Number (e.g. `2`).
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `max` property.
*/
max: {
type: String
},
/**
* Set to true to auto-validate the input value. Bind this to the `<paper-input-container>`'s
* `autoValidate` property.
*/
autoValidate: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* Set to true to mark the input as required. Bind this to the `<input is="iron-input">`'s
* `required` property.
*/
required: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* Set to true to switch to a text-area
*/
multiLine: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* Set to true to disable this input.
*/
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* The initial number of rows.
*
* @attribute rows
* @type number
* @default 3
*/
rows: {
type: Number,
value: 3
},
/**
* The initial number of rows.
*
* @attribute rows
* @type number
* @default 3
*/
maxRows: {
type: Number,
value: 10
},
/**
* The value for this input. Bind this to the `<input is="iron-input">`'s `bindValue`
* property, or the value property of your input that is `notify:true`.
*/
value: {
type:String,
notify:true,
reflectToAttribute: true
},
// HTMLInputElement attributes for binding if needed
/**
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `autocomplete` property.
*/
autocomplete: {
type: String,
value: 'off'
},
// Nonstandard attributes for binding if needed
/**
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `autocapitalize` property.
*/
autocapitalize: {
type: String,
value: 'none'
},
/**
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `autocorrect` property.
*/
autocorrect: {
type: String,
value: 'off'
}
},
_checkRowValidity: function(row){
if(row <= 1)
return false;
return true;
},
validate: function(){
if ((typeof(this.value)).toLowerCase() === 'string') {
this.value = this.value.trim();}
return Polymer.dom(this.root).querySelector('#input').validate();
}
});
</script>