| OLD | NEW |
| (Empty) |
| 1 | |
| 2 | |
| 3 Polymer('core-input', { | |
| 4 | |
| 5 publish: { | |
| 6 | |
| 7 /** | |
| 8 * The "committed" value of the input, ie. the input value when the user | |
| 9 * hits the "enter" key or blurs the input after changing the value. You | |
| 10 * can bind to this value instead of listening for the "change" event. | |
| 11 * Setting this property has no effect on the input value. | |
| 12 * | |
| 13 * @attribute committedValue | |
| 14 * @type string | |
| 15 * @default '' | |
| 16 */ | |
| 17 committedValue: '', | |
| 18 | |
| 19 /** | |
| 20 * Set to true to prevent invalid input from being entered. | |
| 21 * | |
| 22 * @attribute preventInvalidInput | |
| 23 * @type boolean | |
| 24 * @default false | |
| 25 */ | |
| 26 preventInvalidInput: false | |
| 27 | |
| 28 }, | |
| 29 | |
| 30 previousValidInput: '', | |
| 31 | |
| 32 eventDelegates: { | |
| 33 input: 'inputAction', | |
| 34 change: 'changeAction' | |
| 35 }, | |
| 36 | |
| 37 ready: function() { | |
| 38 /* set ARIA attributes */ | |
| 39 this.disabledHandler(); | |
| 40 this.placeholderHandler(); | |
| 41 }, | |
| 42 | |
| 43 attributeChanged: function(attr, old) { | |
| 44 if (this[attr + 'Handler']) { | |
| 45 this[attr + 'Handler'](old); | |
| 46 } | |
| 47 }, | |
| 48 | |
| 49 disabledHandler: function() { | |
| 50 if (this.disabled) { | |
| 51 this.setAttribute('aria-disabled', ''); | |
| 52 } else { | |
| 53 this.removeAttribute('aria-disabled'); | |
| 54 } | |
| 55 }, | |
| 56 | |
| 57 placeholderHandler: function() { | |
| 58 if (this.placeholder) { | |
| 59 this.setAttribute('aria-label', this.placeholder); | |
| 60 } else { | |
| 61 this.removeAttribute('aria-label'); | |
| 62 } | |
| 63 }, | |
| 64 | |
| 65 /** | |
| 66 * Commits the `value` to `committedValue` | |
| 67 * | |
| 68 * @method commit | |
| 69 */ | |
| 70 commit: function() { | |
| 71 this.committedValue = this.value; | |
| 72 }, | |
| 73 | |
| 74 changeAction: function() { | |
| 75 this.commit(); | |
| 76 }, | |
| 77 | |
| 78 inputAction: function(e) { | |
| 79 if (this.preventInvalidInput) { | |
| 80 if (!e.target.validity.valid) { | |
| 81 e.target.value = this.previousValidInput; | |
| 82 } else { | |
| 83 this.previousValidInput = e.target.value; | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 }); | |
| 89 | |
| OLD | NEW |