Skip to content

Commit

Permalink
autoValidate and special case for mm-repeater in mm-form
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykoerber committed Mar 2, 2016
1 parent b5e8158 commit 2a0452b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/mm-form/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@
label: 'Select a Color'
},
'repeater': {
// TODO: Do the validation in the form
// validation: function(name, value, data, field, view) {
// return field.validate();
// },
parentEle: null,
errorMsgEle: null,
errorMsg: 'You need to select some stuff',
label: 'Repeat Things'
}
// 'empty' : {}
Expand Down Expand Up @@ -198,8 +191,6 @@
testForm.config = config;
// testForm.data = data;



testForm.addEventListener('serialize-form', function(e){
console.log('serialize-form', e.detail);
});
Expand Down
17 changes: 15 additions & 2 deletions src/mm-form/mm-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
value: true,
notify: true
},
autoValidate: {
type: Boolean,
value: true
},
// Footer related
footerMessages: {
type: Object,
Expand Down Expand Up @@ -275,7 +279,7 @@
this.unsaved = this._diffData();
}

if (validation) this._validateField(key, value);
if (validation && this.autoValidate) this._validateField(key, value);

// show messaging in the footer
if (this.unsaved && this.showUnsavedMessage) {
Expand Down Expand Up @@ -338,6 +342,15 @@
} else if (validation && noValidate) {
// clean up prior validations if they were there
this.resetFieldValidation(key);
} else {
// special case for mm-repeater
// mm-repeater will handle it's own validation
var field = this.config[key].field,
tagName = field.tagName.toLowerCase();

if (tagName === 'mm-repeater') {
field.validate();
}
}

// show messaging in the footer
Expand All @@ -350,7 +363,7 @@
},

_validateField: function(key, value) {
var valid = null,
var valid = false,
field = this.config[key].field,
validation = this.config[key].validation,
errorMsg = this.config[key].errorMsg,
Expand Down

0 comments on commit 2a0452b

Please sign in to comment.