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 */ | |
5 | 4 |
6 Polymer('gaia-input-form', (function() { | 5 Polymer({ |
7 return { | 6 is: 'gaia-input-form', |
8 onButtonClicked: function() { | 7 |
9 this.fire('submit'); | 8 properties: { |
| 9 disabled: { |
| 10 type: Boolean, |
| 11 observer: 'onDisabledChanged_', |
10 }, | 12 }, |
11 | 13 |
12 onKeyDown: function(e) { | 14 buttonText: String |
13 if (e.keyCode == 13 && !this.$.button.disabled) | 15 }, |
14 this.onButtonClicked(); | |
15 }, | |
16 | 16 |
17 set disabled(value) { | 17 onButtonClicked_: function() { |
18 var controls = this.querySelectorAll( | 18 this.fire('submit'); |
19 ':host /deep/ [role="button"], :host /deep/ [is="core-input"]'); | 19 }, |
20 for (var i = 0, control; control = controls[i]; ++i) | 20 |
21 control.disabled = value; | 21 getInputs_: function() { |
22 }, | 22 return Polymer.dom(this.$.inputs).getDistributedNodes(); |
23 }; | 23 }, |
24 })()); | 24 |
| 25 onKeyDown_: function(e) { |
| 26 if (e.keyCode != 13 || this.$.button.disabled) |
| 27 return; |
| 28 if (this.getInputs_().indexOf(e.target) == -1) |
| 29 return; |
| 30 this.onButtonClicked_(); |
| 31 }, |
| 32 |
| 33 getControls_: function() { |
| 34 var controls = this.getInputs_(); |
| 35 controls.push(this.$.button); |
| 36 return controls.concat(Polymer.dom(this).querySelectorAll('gaia-button')); |
| 37 }, |
| 38 |
| 39 onDisabledChanged_: function(disabled) { |
| 40 this.getControls_().forEach(function(control) { |
| 41 control.disabled = disabled; |
| 42 }); |
| 43 } |
| 44 }); |
OLD | NEW |