|
112 | 112 |
|
113 | 113 | _initForm: function(data) { |
114 | 114 | for (var key in data) { |
115 | | - var name = key, |
116 | | - label = this.data[key].label, |
| 115 | + var label = this.data[key].label, |
117 | 116 | errorMsg = this.data[key].errorMsg, |
118 | | - field = Polymer.dom(this).querySelector('[name='+name+']'), |
| 117 | + field = Polymer.dom(this).querySelector('[name='+key+']'), |
119 | 118 | parentEle = Polymer.dom(field).parentNode, |
120 | 119 | value = this.data[key].value || null; |
121 | 120 |
|
|
127 | 126 |
|
128 | 127 | // Store the field and parent element just in case |
129 | 128 | // we need to reference those later |
130 | | - this.data[name].field = field; |
131 | | - this.data[name].parentEle = parentEle; |
| 129 | + this.data[key].field = field; |
| 130 | + this.data[key].parentEle = parentEle; |
132 | 131 |
|
133 | | - this._updateData(name, value); |
134 | | - this._createErrorMsg(name, parentEle, errorMsg); |
135 | | - this._createLabel(name, parentEle, field, label); |
| 132 | + this._updateData(key, value); |
| 133 | + this._createErrorMsg(key, parentEle, errorMsg); |
| 134 | + this._createLabel(key, parentEle, field, label); |
136 | 135 |
|
137 | 136 | // Populate the fields if necessary |
138 | 137 | if (!field.value && value) { |
|
192 | 191 | e.model.item.callback(e,this); |
193 | 192 | }, |
194 | 193 |
|
| 194 | + _handleFooter: function(message, type, show) { |
| 195 | + this._footerMessage = message; |
| 196 | + this._footerType = type; |
| 197 | + this._showFooterMessage = show; |
| 198 | + }, |
| 199 | + |
195 | 200 | _displayMessage: function(_showFooterMessage, showFooterMessages) { |
196 | 201 | return _showFooterMessage && showFooterMessages; |
197 | 202 | }, |
|
211 | 216 |
|
212 | 217 | // show messaging in the footer |
213 | 218 | if (this.unsaved && this.showUnsavedMessage) { |
214 | | - this._footerMessage = this.footerMessages.warning; |
215 | | - this._footerType = 'warning'; |
216 | | - this._showFooterMessage = true; |
| 219 | + this._handleFooter(this.footerMessages.warning, 'warning', true); |
217 | 220 | } else { |
218 | 221 | this._showFooterMessage = false; |
219 | 222 | } |
|
241 | 244 | this._validFields = []; |
242 | 245 |
|
243 | 246 | for (var key in data) { |
244 | | - var name = key, |
245 | | - value = this._formData[key], |
246 | | - valid = this._validateField(name, value); |
| 247 | + var value = this._formData[key], |
| 248 | + valid = this._validateField(key, value); |
247 | 249 |
|
248 | 250 | // Store valid and invalid for this validation pass |
249 | 251 | if (valid) { |
250 | | - this._validFields.push(name); |
| 252 | + this._validFields.push(key); |
251 | 253 | } else { |
252 | | - this._invalidFields.push(name); |
| 254 | + this._invalidFields.push(key); |
253 | 255 | } |
254 | 256 |
|
255 | 257 | // show messaging in the footer |
256 | 258 | if (this._invalidFields.length > 0) { |
257 | | - this._footerMessage = this.footerMessages.error; |
258 | | - this._footerType = 'error'; |
259 | | - this._showFooterMessage = true; |
| 259 | + this._handleFooter(this.footerMessages.error, 'error', true); |
260 | 260 | } else { |
261 | | - this._footerMessage = this.footerMessages.success; |
262 | | - this._footerType = 'success'; |
263 | | - this._showFooterMessage = true; |
| 261 | + this._handleFooter(this.footerMessages.success, 'success', true); |
264 | 262 | } |
265 | 263 | } |
266 | 264 | }, |
267 | 265 |
|
268 | 266 | // TODO: Secondary validation pass returned from server-side validation |
269 | 267 | // Will need to assume that the front end validation rules were wrong |
270 | 268 | // and there needs to be a new method to bypass the current infrastructure |
271 | | - // to display this messaging |
| 269 | + // to display this messaging... |
| 270 | + updateInvalidFields: function(data) { |
| 271 | + // TODO: This is also a bad assumption... the old validation infrastructure |
| 272 | + // remains so all we're doing here is showing the messaging... |
| 273 | + // not feasible to update the 'actual' validation rules unless there is a |
| 274 | + // new config passed, with new rules |
| 275 | + for (var key in data) { |
| 276 | + var field = this.data[key].field, |
| 277 | + errorMsgEle = this.data[key].errorMsgEle, |
| 278 | + errorMsg = data[key]; |
| 279 | + |
| 280 | + // this.data[key].errorMsg = errorMsg; |
| 281 | + errorMsgEle.message = errorMsg; |
| 282 | + field.error = errorMsgEle.visible = true; |
| 283 | + } |
| 284 | + |
| 285 | + this._handleFooter(this.footerMessages.error, 'error', true); |
| 286 | + }, |
272 | 287 |
|
273 | 288 | _validateField: function(name, value) { |
274 | 289 | var valid = false, |
|
0 commit comments