From f1f8c74175f446ef9d032010cb107ef85f392748 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 21 Feb 2018 11:09:27 +0100 Subject: [PATCH] refactor watcher added requiredField --- client/core/src/components/watcher/watcher.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/core/src/components/watcher/watcher.js b/client/core/src/components/watcher/watcher.js index 12b8af599..f4ecbf6ea 100644 --- a/client/core/src/components/watcher/watcher.js +++ b/client/core/src/components/watcher/watcher.js @@ -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: '<',