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