refactor watcher added requiredField
This commit is contained in:
parent
c983859cde
commit
f1f8c74175
|
@ -101,10 +101,21 @@ export default class Watcher extends Component {
|
||||||
(resolve, reject) => this.noChanges(reject)
|
(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)
|
? this.copyInNewObject(this.data)
|
||||||
: getModifiedData(this.data, this.orgData);
|
: 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) {
|
if (this.save && this.save.accept) {
|
||||||
this.save.model = changedData; // this.copyInNewObject(changedData);
|
this.save.model = changedData; // this.copyInNewObject(changedData);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -213,6 +224,7 @@ ngModule.component('vnWatcher', {
|
||||||
bindings: {
|
bindings: {
|
||||||
url: '@?',
|
url: '@?',
|
||||||
idField: '@?',
|
idField: '@?',
|
||||||
|
requiredField: '@?',
|
||||||
data: '<',
|
data: '<',
|
||||||
form: '<',
|
form: '<',
|
||||||
save: '<',
|
save: '<',
|
||||||
|
|
Loading…
Reference in New Issue