OLD | NEW |
(Empty) | |
| 1 /* Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 |
| 6 Polymer('gaia-input', (function() { |
| 7 var INPUT_EMAIL_PATTERN = "^[a-zA-Z0-9.!#$%&'*+=?^_`{|}~-]+(@[^\\s@]+)?$"; |
| 8 |
| 9 return { |
| 10 required: false, |
| 11 |
| 12 ready: function() { |
| 13 this.typeChanged(); |
| 14 }, |
| 15 |
| 16 onKeyDown: function(e) { |
| 17 this.isInvalid = false; |
| 18 }, |
| 19 |
| 20 setDomainVisibility: function() { |
| 21 this.$.domainLabel.hidden = (this.type !== 'email') || !this.domain || |
| 22 (this.value.indexOf('@') !== -1); |
| 23 }, |
| 24 |
| 25 onTap: function() { |
| 26 this.isInvalid = false; |
| 27 }, |
| 28 |
| 29 focus: function() { |
| 30 this.$.input.focus(); |
| 31 }, |
| 32 |
| 33 checkValidity: function() { |
| 34 var isValid = this.$.input.validity.valid; |
| 35 this.isInvalid = !isValid; |
| 36 return isValid; |
| 37 }, |
| 38 |
| 39 typeChanged: function() { |
| 40 if (this.type == 'email') { |
| 41 this.$.input.pattern = INPUT_EMAIL_PATTERN; |
| 42 this.$.input.type = 'text'; |
| 43 } else { |
| 44 this.$.input.removeAttribute('pattern'); |
| 45 this.$.input.type = this.type; |
| 46 } |
| 47 this.setDomainVisibility(); |
| 48 }, |
| 49 |
| 50 valueChanged: function() { |
| 51 this.setDomainVisibility(); |
| 52 }, |
| 53 |
| 54 domainChanged: function() { |
| 55 this.setDomainVisibility(); |
| 56 } |
| 57 }; |
| 58 })()); |
| 59 |
OLD | NEW |