|
1 | | -import { detectFieldChange } from 'Modules/@apostrophecms/schema/lib/detectChange'; |
2 | 1 | import { getConditionTypesObject } from '../lib/conditionalFields'; |
3 | 2 |
|
4 | 3 | export default { |
@@ -130,9 +129,6 @@ export default { |
130 | 129 | ...item, |
131 | 130 | required |
132 | 131 | }, |
133 | | - value: { |
134 | | - data: this.modelValue.data[item.name] |
135 | | - }, |
136 | 132 | serverError: this.serverErrors && this.serverErrors[item.name], |
137 | 133 | modifiers: this.computeModifiers(item) |
138 | 134 | } |
@@ -167,6 +163,13 @@ export default { |
167 | 163 | } |
168 | 164 | }, |
169 | 165 | watch: { |
| 166 | + fieldState: { |
| 167 | + deep: 2, |
| 168 | + handler() { |
| 169 | + this.updateNextAndEmit(); |
| 170 | + }, |
| 171 | + flush: 'post' |
| 172 | + }, |
170 | 173 | schema() { |
171 | 174 | this.populateDocData(); |
172 | 175 | }, |
@@ -211,6 +214,7 @@ export default { |
211 | 214 | created() { |
212 | 215 | this.populateDocData(); |
213 | 216 | }, |
| 217 | + |
214 | 218 | methods: { |
215 | 219 | emitValidate() { |
216 | 220 | this.$emit('validate'); |
@@ -269,53 +273,18 @@ export default { |
269 | 273 | if (!this.schemaReady) { |
270 | 274 | return; |
271 | 275 | } |
272 | | - const oldHasErrors = this.next.hasErrors; |
273 | | - // destructure these for non-linked comparison |
274 | | - const oldFieldState = { ...this.next.fieldState }; |
275 | | - const newFieldState = { ...this.fieldState }; |
276 | | - |
277 | | - let changeFound = false; |
278 | | - |
279 | 276 | this.next.hasErrors = false; |
280 | | - this.next.fieldState = { ...this.fieldState }; |
281 | | - |
282 | 277 | this.schema |
283 | 278 | .filter(field => this.displayComponent(field)) |
284 | 279 | .forEach(field => { |
285 | 280 | if (this.fieldState[field.name].error) { |
286 | 281 | this.next.hasErrors = true; |
287 | 282 | } |
288 | | - // This simply check if a field has changed since it has been |
289 | | - // instantiated |
290 | | - if ( |
291 | | - this.fieldState[field.name].data !== undefined && |
292 | | - detectFieldChange( |
293 | | - field, |
294 | | - this.next.data[field.name], |
295 | | - this.fieldState[field.name].data |
296 | | - ) |
297 | | - ) { |
298 | | - changeFound = true; |
299 | | - |
300 | | - // fieldState never gets the relationships postprocessed data |
301 | | - // that's why it gets seen as different than next all the time |
302 | | - this.next.data[field.name] = this.fieldState[field.name].data; |
303 | | - } else { |
304 | | - this.next.data[field.name] = this.modelValue.data[field.name]; |
305 | | - } |
| 283 | + this.next.data[field.name] = this.fieldState[field.name].data; |
306 | 284 | }); |
307 | | - if ( |
308 | | - oldHasErrors !== this.next.hasErrors || |
309 | | - oldFieldState !== newFieldState |
310 | | - ) { |
311 | | - // Otherwise the save button may never unlock |
312 | | - changeFound = true; |
313 | | - } |
314 | 285 |
|
315 | | - if (changeFound) { |
316 | | - // ... removes need for deep watch at parent level |
317 | | - this.$emit('update:model-value', { ...this.next }); |
318 | | - } |
| 286 | + this.next.fieldState = { ...this.fieldState }; |
| 287 | + this.$emit('update:model-value', { ...this.next }); |
319 | 288 | }, |
320 | 289 | displayComponent({ name, hidden = false }) { |
321 | 290 | if (hidden === true) { |
|
0 commit comments