refactor watcher added requiredField

This commit is contained in:
Daniel Herrero 2018-02-21 11:09:27 +01:00
parent c983859cde
commit f1f8c74175
1 changed files with 13 additions and 1 deletions

View File

@ -101,10 +101,21 @@ export default class Watcher extends Component {
(resolve, reject) => this.noChanges(reject)
);
}
let changedData = (this.$attrs.save && this.$attrs.save.toLowerCase() === 'post')
let isPost = (this.$attrs.save && this.$attrs.save.toLowerCase() === 'post');
let changedData = isPost
? this.copyInNewObject(this.data)
: getModifiedData(this.data, this.orgData);
if (this.requiredField && !changedData[this.requiredField]) {
let required = this.data[this.requiredField] || this.orgData[this.requiredField];
if (required === undefined) {
return new Promise(
(resolve, reject) => this.invalidForm(reject)
);
}
changedData[this.requiredField] = required;
}
if (this.save && this.save.accept) {
this.save.model = changedData; // this.copyInNewObject(changedData);
return new Promise((resolve, reject) => {
@ -213,6 +224,7 @@ ngModule.component('vnWatcher', {
bindings: {
url: '@?',
idField: '@?',
requiredField: '@?',
data: '<',
form: '<',
save: '<',