Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/resources/settings/input/input.js

Issue 1368733002: Introduce cr-settings-input and eliminate cr-input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_532540_elim_cr_toggle_button
Patch Set: More feedback Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 * @fileoverview
7 * `cr-settings-input` is a single-line text field for user input associated
8 * with a pref value.
9 *
10 * @element cr-settings-input
11 */
12 Polymer({
13 is: 'cr-settings-input',
14
15 behaviors: [PolicyControllable],
16
17 properties: {
18 /**
19 * The preference object to control.
20 * @type {chrome.settingsPrivate.PrefObject|undefined}
21 */
22 pref: {
23 type: Object,
24 notify: true,
25 observer: 'prefChanged_'
26 },
27
28 /**
29 * The current value of the input, reflected to/from |pref|.
30 */
31 value: {
32 type: String,
33 value: '',
34 notify: true,
35 },
36
37 /**
38 * Set to true to disable editing the input.
39 */
40 disabled: {
41 type: Boolean,
42 value: false,
43 reflectToAttribute: true
44 },
45
46 /** Propagate the label property. */
47 label: { type: String },
48
49 /** Propagate the no-label-float property. */
50 noLabelFloat: { type: Boolean, value: false },
51
52 /** Propagate the required property. */
53 required: { type: Boolean, value: false },
54
55 /** Propagate the pattern property. */
56 pattern: { type: String },
57
58 /** Propagate the type property. */
59 type: { type: String },
60
61 /** Propagate the errorMessage property. */
62 errorMessage: { type: String },
63 },
64
65 /** @override */
66 ready: function() {
67 this.$.events.forward(this.$.input, ['change']);
68 },
69
70 /**
71 * Focuses the 'input' element.
72 */
73 focus: function() {
74 this.$.input.inputElement.focus();
75 },
76
77 /**
78 * Polymer changed observer for |pref|.
79 * @private
80 */
81 prefChanged_: function() {
82 if (!this.pref)
83 return;
84
85 // Ignore updates while the input is focused so that user input is not
86 // overwritten.
87 if (this.$.input.focused)
88 return;
89
90 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
91 this.value = this.pref.value.toString();
92 } else {
93 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
94 this.pref.type == chrome.settingsPrivate.PrefType.URL);
95 this.value = /** @type {string} */(this.pref.value);
96 }
97 },
98
99 /**
100 * Blur method for paper-input. Only update the pref value on a blur event.
101 * @private
102 */
103 onBlur_: function() {
104 if (!this.pref)
105 return;
106
107 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
108 if (!this.value)
109 return; // Ignore empty input field
dschuyler 2015/09/24 20:39:05 Maybe set this.value to pref.value if value is emp
stevenjb 2015/09/24 21:22:15 Eventually we should do proper validation, but yea
110 var n = parseInt(this.value, 10);
111 if (isNaN(n)) {
112 console.error('Bad value for numerical pref: ' + this.value);
113 return;
114 }
115 this.set('pref.value', n);
116 } else {
117 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
118 this.pref.type == chrome.settingsPrivate.PrefType.URL);
119 this.set('pref.value', this.value);
120 }
121 },
122
123 /**
124 * @param {boolean} disabled
125 * @param {?chrome.settingsPrivate.PrefObject} pref
126 * @return {boolean} Whether the element should be disabled.
127 * @private
128 */
129 isDisabled_: function(disabled, pref) {
130 return disabled || this.isPolicyControlled(pref);
131 },
132 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698