Skip to content

Commit 14597b6

Browse files
Updates to mm-form
1 parent 23223ec commit 14597b6

2 files changed

Lines changed: 41 additions & 32 deletions

File tree

src/mm-form/index.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,9 @@
114114
},
115115
// returned from server-side validation(?)
116116
returnedData = {
117-
'input' : {
118-
errorMsg: 'Type a number greater than 0'
119-
},
120-
'dropdown' : {
121-
errorMsg: 'Select a different item'
122-
},
123-
'radio' : {
124-
errorMsg: 'Select Green'
125-
}
117+
'input' : 'Type a number greater than 0',
118+
'dropdown' : 'Select a different item',
119+
'radio' : 'Select Green'
126120
};
127121

128122
window.addEventListener('WebComponentsReady', function(e) {

src/mm-form/mm-form.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@
112112

113113
_initForm: function(data) {
114114
for (var key in data) {
115-
var name = key,
116-
label = this.data[key].label,
115+
var label = this.data[key].label,
117116
errorMsg = this.data[key].errorMsg,
118-
field = Polymer.dom(this).querySelector('[name='+name+']'),
117+
field = Polymer.dom(this).querySelector('[name='+key+']'),
119118
parentEle = Polymer.dom(field).parentNode,
120119
value = this.data[key].value || null;
121120

@@ -127,12 +126,12 @@
127126

128127
// Store the field and parent element just in case
129128
// 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;
132131

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);
136135

137136
// Populate the fields if necessary
138137
if (!field.value && value) {
@@ -192,6 +191,12 @@
192191
e.model.item.callback(e,this);
193192
},
194193

194+
_handleFooter: function(message, type, show) {
195+
this._footerMessage = message;
196+
this._footerType = type;
197+
this._showFooterMessage = show;
198+
},
199+
195200
_displayMessage: function(_showFooterMessage, showFooterMessages) {
196201
return _showFooterMessage && showFooterMessages;
197202
},
@@ -211,9 +216,7 @@
211216

212217
// show messaging in the footer
213218
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);
217220
} else {
218221
this._showFooterMessage = false;
219222
}
@@ -241,34 +244,46 @@
241244
this._validFields = [];
242245

243246
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);
247249

248250
// Store valid and invalid for this validation pass
249251
if (valid) {
250-
this._validFields.push(name);
252+
this._validFields.push(key);
251253
} else {
252-
this._invalidFields.push(name);
254+
this._invalidFields.push(key);
253255
}
254256

255257
// show messaging in the footer
256258
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);
260260
} else {
261-
this._footerMessage = this.footerMessages.success;
262-
this._footerType = 'success';
263-
this._showFooterMessage = true;
261+
this._handleFooter(this.footerMessages.success, 'success', true);
264262
}
265263
}
266264
},
267265

268266
// TODO: Secondary validation pass returned from server-side validation
269267
// Will need to assume that the front end validation rules were wrong
270268
// 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+
},
272287

273288
_validateField: function(name, value) {
274289
var valid = false,

0 commit comments

Comments
 (0)