OLD | NEW |
1 | 1 |
2 | 2 |
3 Polymer({ | 3 Polymer({ |
4 | 4 |
5 is: 'iron-autogrow-textarea', | 5 is: 'iron-autogrow-textarea', |
6 | 6 |
7 behaviors: [ | 7 behaviors: [ |
8 Polymer.IronValidatableBehavior | 8 Polymer.IronFormElementBehavior, |
| 9 Polymer.IronValidatableBehavior, |
| 10 Polymer.IronControlState |
9 ], | 11 ], |
10 | 12 |
11 properties: { | 13 properties: { |
12 | 14 |
13 /** | 15 /** |
14 * Use this property instead of `value` for two-way data binding. | 16 * Use this property instead of `value` for two-way data binding. |
15 */ | 17 */ |
16 bindValue: { | 18 bindValue: { |
17 observer: '_bindValueChanged', | 19 observer: '_bindValueChanged', |
18 type: String | 20 type: String |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 }, | 71 }, |
70 | 72 |
71 /** | 73 /** |
72 * Bound to the textarea's `name` attribute. | 74 * Bound to the textarea's `name` attribute. |
73 */ | 75 */ |
74 name: { | 76 name: { |
75 type: String | 77 type: String |
76 }, | 78 }, |
77 | 79 |
78 /** | 80 /** |
| 81 * The value for this input, same as `bindValue` |
| 82 */ |
| 83 value: { |
| 84 notify: true, |
| 85 type: String, |
| 86 computed: '_computeValue(bindValue)' |
| 87 }, |
| 88 |
| 89 /** |
79 * Bound to the textarea's `placeholder` attribute. | 90 * Bound to the textarea's `placeholder` attribute. |
80 */ | 91 */ |
81 placeholder: { | 92 placeholder: { |
82 type: String | 93 type: String |
83 }, | 94 }, |
84 | 95 |
85 /** | 96 /** |
86 * Bound to the textarea's `readonly` attribute. | 97 * Bound to the textarea's `readonly` attribute. |
87 */ | 98 */ |
88 readonly: { | 99 readonly: { |
(...skipping 15 matching lines...) Expand all Loading... |
104 } | 115 } |
105 | 116 |
106 }, | 117 }, |
107 | 118 |
108 listeners: { | 119 listeners: { |
109 'input': '_onInput' | 120 'input': '_onInput' |
110 }, | 121 }, |
111 | 122 |
112 /** | 123 /** |
113 * Returns the underlying textarea. | 124 * Returns the underlying textarea. |
| 125 * @type HTMLTextAreaElement |
114 */ | 126 */ |
115 get textarea() { | 127 get textarea() { |
116 return this.$.textarea; | 128 return this.$.textarea; |
117 }, | 129 }, |
118 | 130 |
| 131 /** |
| 132 * Returns true if `value` is valid. The validator provided in `validator` |
| 133 * will be used first, if it exists; otherwise, the `textarea`'s validity |
| 134 * is used. |
| 135 * @return {boolean} True if the value is valid. |
| 136 */ |
| 137 validate: function() { |
| 138 // Empty, non-required input is valid. |
| 139 if (!this.required && this.value == '') { |
| 140 this.invalid = false; |
| 141 return true; |
| 142 } |
| 143 |
| 144 var valid; |
| 145 if (this.hasValidator()) { |
| 146 valid = Polymer.IronValidatableBehavior.validate.call(this, this.value); |
| 147 } else { |
| 148 valid = this.$.textarea.validity.valid; |
| 149 this.invalid = !valid; |
| 150 } |
| 151 this.fire('iron-input-validate'); |
| 152 return valid; |
| 153 }, |
| 154 |
119 _update: function() { | 155 _update: function() { |
120 this.$.mirror.innerHTML = this._valueForMirror(); | 156 this.$.mirror.innerHTML = this._valueForMirror(); |
121 | 157 |
122 var textarea = this.textarea; | 158 var textarea = this.textarea; |
123 // If the value of the textarea was updated imperatively, then we | 159 // If the value of the textarea was updated imperatively, then we |
124 // need to manually update bindValue as well. | 160 // need to manually update bindValue as well. |
125 if (textarea && this.bindValue != textarea.value) { | 161 if (textarea && this.bindValue != textarea.value) { |
126 this.bindValue = textarea.value; | 162 this.bindValue = textarea.value; |
127 } | 163 } |
128 }, | 164 }, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 var input = this.textarea; | 199 var input = this.textarea; |
164 if (!input) { | 200 if (!input) { |
165 return; | 201 return; |
166 } | 202 } |
167 this.tokens = (input && input.value) ? input.value.replace(/&/gm, '&')
.replace(/"/gm, '"').replace(/'/gm, ''').replace(/</gm, '<').replace
(/>/gm, '>').split('\n') : ['']; | 203 this.tokens = (input && input.value) ? input.value.replace(/&/gm, '&')
.replace(/"/gm, '"').replace(/'/gm, ''').replace(/</gm, '<').replace
(/>/gm, '>').split('\n') : ['']; |
168 return this._constrain(this.tokens); | 204 return this._constrain(this.tokens); |
169 }, | 205 }, |
170 | 206 |
171 _updateCached: function() { | 207 _updateCached: function() { |
172 this.$.mirror.innerHTML = this._constrain(this.tokens); | 208 this.$.mirror.innerHTML = this._constrain(this.tokens); |
| 209 }, |
| 210 |
| 211 _computeValue: function() { |
| 212 return this.bindValue; |
173 } | 213 } |
174 }) | 214 }) |
OLD | NEW |