5 is: 'paper-input-container',
10 * Set to true to disable the floating label. The label disappears when the input value is
19 * Set to true to always float the floating label.
27 * The attribute to listen for value changes on.
35 * Set to true to auto-validate the input value when it changes.
43 * True if the input is invalid. This property is set automatically when the input value
44 * changes if auto-validating, or when the `iron-input-valid` event is heard from a child.
47 observer: '_invalidChanged',
53 * True if the input has focus.
63 // do not set a default value here intentionally - it will be initialized lazily when a
64 // distributed child is attached, which may occur before configuration for this element
75 value: 'input,textarea,.paper-input-input'
81 return this._onFocus.bind(this);
88 return this._onBlur.bind(this);
95 return this._onInput.bind(this);
102 return this._onValueChanged.bind(this);
109 'addon-attached': '_onAddonAttached',
110 'iron-input-validate': '_onIronInputValidate'
113 get _valueChangedEvent() {
114 return this.attrForValue + '-changed';
117 get _propertyForValue() {
118 return Polymer.CaseMap.dashToCamelCase(this.attrForValue);
121 get _inputElement() {
122 return Polymer.dom(this).querySelector(this._inputSelector);
129 this.addEventListener('focus', this._boundOnFocus, true);
130 this.addEventListener('blur', this._boundOnBlur, true);
131 if (this.attrForValue) {
132 this._inputElement.addEventListener(this._valueChangedEvent, this._boundValueChanged);
134 this.addEventListener('input', this._onInput);
138 attached: function() {
139 this._handleValue(this._inputElement);
142 _onAddonAttached: function(event) {
146 var target = event.target;
147 if (this._addons.indexOf(target) === -1) {
148 this._addons.push(target);
149 if (this.isAttached) {
150 this._handleValue(this._inputElement);
155 _onFocus: function() {
156 this._setFocused(true);
159 _onBlur: function() {
160 this._setFocused(false);
163 _onInput: function(event) {
164 this._handleValue(event.target);
167 _onValueChanged: function(event) {
168 this._handleValue(event.target);
171 _handleValue: function(inputElement) {
172 var value = inputElement[this._propertyForValue] || inputElement.value;
174 if (this.autoValidate) {
176 if (inputElement.validate) {
177 valid = inputElement.validate(value);
179 valid = inputElement.checkValidity();
181 this.invalid = !valid;
184 // type="number" hack needed because this.value is empty until it's valid
185 if (value || value === 0 || (inputElement.type === 'number' && !inputElement.checkValidity())) {
186 this._inputHasContent = true;
188 this._inputHasContent = false;
192 inputElement: inputElement,
194 invalid: this.invalid
198 _onIronInputValidate: function(event) {
199 this.invalid = this._inputElement.invalid;
202 _invalidChanged: function() {
204 this.updateAddons({invalid: this.invalid});
209 * Call this to update the state of add-ons.
210 * @param {Object} state Add-on state.
212 updateAddons: function(state) {
213 for (var addon, index = 0; addon = this._addons[index]; index++) {
218 _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused, invalid, _inputHasContent) {
219 var cls = 'input-content';
221 var label = this.querySelector('label');
223 if (alwaysFloatLabel || _inputHasContent) {
224 cls += ' label-is-floating';
226 cls += ' is-invalid';
227 } else if (focused) {
228 cls += " label-is-highlighted";
230 // The label might have a horizontal offset if a prefix element exists
231 // which needs to be undone when displayed as a floating label.
232 if (this.$.prefix && label && label.offsetParent &&
233 Polymer.dom(this.$.prefix).getDistributedNodes().length > 0) {
234 label.style.left = -label.offsetParent.offsetLeft + 'px';
237 // When the label is not floating, it should overlap the input element.
239 label.style.left = 0;
243 if (_inputHasContent) {
244 cls += ' label-is-hidden';
250 _computeUnderlineClass: function(focused, invalid) {
251 var cls = 'underline';
253 cls += ' is-invalid';
254 } else if (focused) {
255 cls += ' is-highlighted'
260 _computeAddOnContentClass: function(focused, invalid) {
261 var cls = 'add-on-content';
263 cls += ' is-invalid';
264 } else if (focused) {
265 cls += ' is-highlighted'