3 Polymer('core-input', {
6 * Placeholder text that hints to the user what can be entered in
9 * @attribute placeholder
16 * If true, this input cannot be focused and the user cannot change
26 * If true, the user cannot modify the value of the input.
35 * If true, this input will automatically gain focus on page load.
37 * @attribute autofocus
44 * If true, this input accepts multi-line input like a `<textarea>`
46 * @attribute multiline
53 * (multiline only) The height of this text input in rows. The input
54 * will scroll internally if more input is entered beyond the size
55 * of the component. This property is meaningless if multiline is
56 * false. You can also set this property to "fit" and size the
57 * component with CSS to make the input fit the CSS size.
66 * The current value of this input. Changing inputValue programmatically
67 * will cause value to be out of sync. Instead, change value directly
68 * or call commit() after changing inputValue.
70 * @attribute inputValue
77 * The value of the input committed by the user, either by changing the
78 * inputValue and blurring the input, or by hitting the `enter` key.
87 * Set the input type. Not supported for `multiline`.
96 * If true, the input is invalid if its value is null.
105 * A regular expression to validate the input value against. See
106 * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes
107 * for more info. Not supported if `multiline` is true.
113 // FIXME(yvonne): The default is set to .* because we can't bind to pattern such
114 // that the attribute is unset if pattern is null.
118 * If set, the input is invalid if the value is less than this property. See
119 * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes
120 * for more info. Not supported if `multiline` is true.
127 * If set, the input is invalid if the value is greater than this property. See
128 * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes
129 * for more info. Not supported if `multiline` is true.
136 * If set, the input is invalid if the value is not `min` plus an integral multiple
137 * of this property. See
138 * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes
139 * for more info. Not supported if `multiline` is true.
146 * The maximum length of the input value.
148 * @attribute maxlength
154 * If this property is true, the text input's inputValue failed validation.
164 this.handleTabindex(this.getAttribute('tabindex'));
167 invalidChanged: function() {
168 this.classList
.toggle('invalid', this.invalid
);
169 this.fire('input-'+ (this.invalid
? 'invalid' : 'valid'), {value
: this.inputValue
});
172 inputValueChanged: function() {
173 this.updateValidity_();
176 valueChanged: function() {
177 this.inputValue
= this.value
;
180 requiredChanged: function() {
181 this.updateValidity_();
184 attributeChanged: function(attr
, oldVal
, curVal
) {
185 if (attr
=== 'tabindex') {
186 this.handleTabindex(curVal
);
190 handleTabindex: function(tabindex
) {
192 this.$.input
.setAttribute('tabindex', -1);
194 this.$.input
.removeAttribute('tabindex');
199 * Commits the inputValue to value.
204 this.value
= this.inputValue
;
207 updateValidity_: function() {
208 if (this.$.input
.willValidate
) {
209 this.invalid
= !this.$.input
.validity
.valid
;
213 keydownAction: function() {
214 // for type = number, the value is the empty string unless the input is a valid number.
215 // FIXME(yvonne): check other types
216 if (this.type
=== 'number') {
217 this.async(function() {
218 this.updateValidity_();
223 inputChangeAction: function() {
225 if (!window
.ShadowDOMPolyfill
) {
226 // re-fire event that does not bubble across shadow roots
227 this.fire('change', null, this);
231 focusAction: function(e
) {
232 if (this.getAttribute('tabindex') > 0) {
233 // Forward focus to the inner input if tabindex is set on the element
234 // This will not cause an infinite loop because focus will not fire on the <input>
235 // again if it's already focused.
236 this.$.input
.focus();
240 inputFocusAction: function(e
) {
241 if (window
.ShadowDOMPolyfill
) {
242 // re-fire non-bubbling event if polyfill
243 this.fire('focus', null, this, false);
247 inputBlurAction: function() {
248 if (window
.ShadowDOMPolyfill
) {
249 // re-fire non-bubbling event
250 this.fire('blur', null, this, false);
255 // forward blur method to the internal input / textarea element
260 // forward click method to the internal input / textarea element
261 this.$.input
.click();
265 // forward focus method to the internal input / textarea element
266 this.$.input
.focus();
270 // forward select method to the internal input / textarea element
271 this.$.input
.focus();
274 setSelectionRange: function(selectionStart
, selectionEnd
, selectionDirection
) {
275 // forward setSelectionRange method to the internal input / textarea element
276 this.$.input
.setSelectionRange(selectionStart
, selectionEnd
, selectionDirection
);
279 setRangeText: function(replacement
, start
, end
, selectMode
) {
280 // forward setRangeText method to the internal input element
281 if (!this.multiline
) {
282 this.$.input
.setRangeText(replacement
, start
, end
, selectMode
);
286 stepDown: function(n
) {
287 // forward stepDown method to the internal input element
288 if (!this.multiline
) {
289 this.$.input
.stepDown(n
);
293 stepUp: function(n
) {
294 // forward stepUp method to the internal input element
295 if (!this.multiline
) {
296 this.$.input
.stepUp(n
);
301 return this.$.input
.willValidate
;
305 return this.$.input
.validity
;
308 get validationMessage() {
309 return this.$.input
.validationMessage
;
312 checkValidity: function() {
313 var r
= this.$.input
.checkValidity();
314 this.updateValidity_();
318 setCustomValidity: function(message
) {
319 this.$.input
.setCustomValidity(message
);
320 this.updateValidity_();