Chromium Code Reviews| Index: chrome/browser/resources/settings/controls/settings_input.js |
| diff --git a/chrome/browser/resources/settings/controls/settings_input.js b/chrome/browser/resources/settings/controls/settings_input.js |
| index ea075476fe84ae7cda2a7d7c44a5a93eb1072565..bfca304863cea56e502b503060599ab35bc37607 100644 |
| --- a/chrome/browser/resources/settings/controls/settings_input.js |
| +++ b/chrome/browser/resources/settings/controls/settings_input.js |
| @@ -18,9 +18,7 @@ Polymer({ |
| * @type {!chrome.settingsPrivate.PrefObject|undefined} |
| * @override |
| */ |
| - pref: { |
| - observer: 'prefChanged_' |
| - }, |
| + pref: {observer: 'prefChanged_'}, |
| /* The current value of the input, reflected to/from |pref|. */ |
| value: { |
| @@ -30,24 +28,26 @@ Polymer({ |
| }, |
| /* Set to true to disable editing the input. */ |
| - disabled: { |
| + disabled: {type: Boolean, value: false, reflectToAttribute: true}, |
| + |
| + canTab: Boolean, |
| + |
| + invalid: { |
| type: Boolean, |
| value: false, |
| - reflectToAttribute: true |
| + notify: true, |
|
dpapad
2017/03/24 01:39:31
Is this needed? From the docs, this is only applic
scottchen
2017/03/24 20:48:54
Based on your comment regarding using data-binding
|
| }, |
| - canTab: Boolean, |
| - |
| /* Properties for paper-input. This is not strictly necessary. |
| * Though it does define the types for the closure compiler. */ |
| - errorMessage: { type: String }, |
| - label: { type: String }, |
| - noLabelFloat: { type: Boolean, value: false }, |
| - pattern: { type: String }, |
| - readonly: { type: Boolean, value: false }, |
| - required: { type: Boolean, value: false }, |
| - stopKeyboardEventPropagation: { type: Boolean, value: false }, |
| - type: { type: String }, |
| + errorMessage: {type: String}, |
| + label: {type: String}, |
| + noLabelFloat: {type: Boolean, value: false}, |
| + pattern: {type: String}, |
| + readonly: {type: Boolean, value: false}, |
| + required: {type: Boolean, value: false}, |
| + stopKeyboardEventPropagation: {type: Boolean, value: false}, |
| + type: {type: String}, |
| }, |
| /** |
| @@ -103,10 +103,14 @@ Polymer({ |
| if (!this.pref) |
| return; |
| + if (this.invalid) { |
| + this.resetValue_(); |
| + return; |
| + } |
| + |
| if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { |
| if (!this.value) { |
| - // Ignore empty input field and restore value. |
| - this.value = this.pref.value.toString(); |
| + this.resetValue_(); |
| return; |
| } |
| var n = parseInt(this.value, 10); |
| @@ -122,17 +126,29 @@ Polymer({ |
| } |
| }, |
| + /** @private */ |
| + resetValue_: function() { |
| + this.invalid = false; |
| + this.setInputValueFromPref_(); |
| + this.$.input.blur(); |
| + }, |
| + |
| /** |
| * Handler for profile name keydowns. |
|
dpapad
2017/03/24 01:39:31
Is this comment obsolete?
scottchen
2017/03/24 20:48:54
Acknowledged.
|
| * @param {!Event} event |
| * @private |
| */ |
| onKeydown_: function(event) { |
| + /* If pressed enter when input is invalid, do not trigger on-change */ |
|
dpapad
2017/03/24 01:39:31
End full sentence comment with a period.
scottchen
2017/03/24 20:48:54
Done.
|
| + if (event.key == 'Enter' && this.invalid) { |
| + event.preventDefault(); |
| + return; |
| + } |
| + |
| if (event.key != 'Escape') |
| return; |
| - this.setInputValueFromPref_(); |
| - this.$.input.blur(); |
| + this.resetValue_(); |
| }, |
| /** |