|
96 | 96 | </div>
|
97 | 97 |
|
98 | 98 | <div id="errorContainer">
|
99 |
| - <div id="error" role="alert" aria-hidden="{{!invalid}}">{{error}}</div> |
| 99 | + <div id="error" role="alert" aria-hidden="{{!invalid}}">{{error || validationMessage}}</div> |
100 | 100 | <div id="errorIcon"></div>
|
101 | 101 | </div>
|
102 | 102 |
|
|
144 | 144 | */
|
145 | 145 | maxRows: 0,
|
146 | 146 |
|
| 147 | + /** |
| 148 | + * The message to display if the input value fails validation. If this |
| 149 | + * is unset or the empty string, a default message is displayed depending |
| 150 | + * on the type of validation error. |
| 151 | + * |
| 152 | + * @attribute error |
| 153 | + * @type string |
| 154 | + */ |
| 155 | + error: '', |
| 156 | + |
147 | 157 | focused: false,
|
148 | 158 | pressed: false,
|
149 | 159 |
|
|
177 | 187 | }
|
178 | 188 | },
|
179 | 189 |
|
| 190 | + toggleLabel: function(force) { |
| 191 | + var v = force !== undefined ? force : this.inputValue; |
| 192 | + |
| 193 | + if (!this.floatingLabel) { |
| 194 | + this.$.label.classList.toggle('hidden', v); |
| 195 | + } |
| 196 | + |
| 197 | + if (this.floatingLabel && !this.focused) { |
| 198 | + this.$.label.classList.toggle('hidden', v); |
| 199 | + this.$.floatedLabel.classList.toggle('hidden', !v); |
| 200 | + } |
| 201 | + }, |
| 202 | + |
180 | 203 | rowsChanged: function() {
|
181 | 204 | if (this.multiline && !isNaN(parseInt(this.rows))) {
|
182 | 205 | this.$.minInputHeight.innerHTML = '';
|
|
209 | 232 | this.resizeInput();
|
210 | 233 | }
|
211 | 234 |
|
212 |
| - if (!this.floatingLabel) { |
213 |
| - this.$.label.classList.toggle('hidden', this.inputValue); |
214 |
| - } |
215 |
| - |
216 |
| - if (this.floatingLabel && !this.focused) { |
217 |
| - this.$.label.classList.toggle('hidden', this.inputValue); |
218 |
| - this.$.floatedLabel.classList.toggle('hidden', !this.inputValue); |
219 |
| - } |
| 235 | + this.toggleLabel(); |
220 | 236 | },
|
221 | 237 |
|
222 | 238 | labelChanged: function() {
|
|
249 | 265 | this.focused = true;
|
250 | 266 | },
|
251 | 267 |
|
| 268 | + shouldFloatLabel: function() { |
| 269 | + // if type = number, the input value is the empty string until a valid number |
| 270 | + // is entered so we must do some hacks here |
| 271 | + return this.inputValue || (this.type === 'number' && !this.validity.valid); |
| 272 | + }, |
| 273 | + |
252 | 274 | inputBlurAction: function() {
|
253 | 275 | this.super(arguments);
|
254 | 276 |
|
255 | 277 | this.$.underlineHighlight.classList.remove('focused');
|
256 | 278 | this.$.caret.classList.remove('focused');
|
| 279 | + |
257 | 280 | if (this.floatingLabel) {
|
258 | 281 | this.$.floatedLabel.classList.remove('focused');
|
259 | 282 | this.$.floatedLabel.classList.remove('focusedColor');
|
260 |
| - if (!this.inputValue) { |
| 283 | + if (!this.shouldFloatLabel()) { |
261 | 284 | this.$.floatedLabel.classList.add('hidden');
|
262 | 285 | }
|
263 | 286 | }
|
264 |
| - if (!this.inputValue) { |
| 287 | + |
| 288 | + // type = number hack. see core-input for more info |
| 289 | + if (!this.shouldFloatLabel()) { |
265 | 290 | this.$.label.classList.remove('hidden');
|
266 | 291 | this.$.label.classList.add('animating');
|
267 | 292 | this.async(function() {
|
268 | 293 | this.$.label.style.webkitTransform = 'none';
|
269 | 294 | this.$.label.style.transform = 'none';
|
270 | 295 | });
|
271 | 296 | }
|
| 297 | + |
272 | 298 | this.focused = false;
|
273 | 299 | },
|
274 | 300 |
|
|
351 | 377 | }
|
352 | 378 | },
|
353 | 379 |
|
| 380 | + keydownAction: function() { |
| 381 | + this.super(); |
| 382 | + |
| 383 | + // more type = number hacks. see core-input for more info |
| 384 | + if (this.type === 'number') { |
| 385 | + this.async(function() { |
| 386 | + if (!this.inputValue) { |
| 387 | + this.toggleLabel(!this.validity.valid); |
| 388 | + } |
| 389 | + }); |
| 390 | + } |
| 391 | + }, |
| 392 | + |
354 | 393 | keypressAction: function() {
|
355 | 394 | if (this.animating) {
|
356 | 395 | this.transitionEndAction();
|
|
0 commit comments