Chromium Code Reviews| 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: { |
| 13 if (e.keyCode == 13 && !this.$.button.disabled) | 15 type: String, |
| 14 this.onButtonClicked(); | 16 reflectToAttribute: true |
|
michaelpg
2015/06/22 20:39:25
Why does this need reflectToAttribute?
dzhioev (left Google)
2015/06/22 21:17:44
it doesn't. Removed.
| |
| 15 }, | 17 } |
| 18 }, | |
| 16 | 19 |
| 17 set disabled(value) { | 20 onButtonClicked_: function() { |
| 18 var controls = this.querySelectorAll( | 21 this.fire('submit'); |
| 19 ':host /deep/ [role="button"], :host /deep/ [is="core-input"]'); | 22 }, |
| 20 for (var i = 0, control; control = controls[i]; ++i) | 23 |
| 21 control.disabled = value; | 24 getInputs_: function() { |
| 22 }, | 25 return Polymer.dom(this.$.inputs).getDistributedNodes(); |
| 23 }; | 26 }, |
| 24 })()); | 27 |
| 28 onKeyDown_: function(e) { | |
| 29 if (e.keyCode != 13 || this.$.button.disabled) | |
| 30 return; | |
| 31 if (this.getInputs_().indexOf(e.target) == -1) | |
| 32 return; | |
| 33 this.onButtonClicked_(); | |
| 34 }, | |
| 35 | |
| 36 getControls_: function() { | |
| 37 var controls = this.getInputs_(); | |
| 38 controls.push(this.$.button); | |
| 39 return controls.concat(Polymer.dom(this).querySelectorAll('gaia-button')); | |
| 40 }, | |
| 41 | |
| 42 onDisabledChanged_: function(disabled) { | |
| 43 this.getControls_().forEach(function(control) { | |
| 44 control.disabled = disabled; | |
| 45 }); | |
| 46 } | |
| 47 }); | |
| OLD | NEW |