@teamnovu/kit-vue-forms 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -2
- package/package.json +1 -1
- package/src/composables/useField.ts +1 -0
- package/src/composables/useForm.ts +1 -1
- package/tests/useForm.test.ts +33 -0
package/dist/index.js
CHANGED
|
@@ -75,7 +75,8 @@ function oe(t) {
|
|
|
75
75
|
() => f(t.initialValue),
|
|
76
76
|
(u) => {
|
|
77
77
|
e.value = Object.freeze(g(u));
|
|
78
|
-
}
|
|
78
|
+
},
|
|
79
|
+
{ flush: "sync" }
|
|
79
80
|
);
|
|
80
81
|
const r = D({
|
|
81
82
|
value: t.value,
|
|
@@ -441,7 +442,7 @@ function Pe(t) {
|
|
|
441
442
|
});
|
|
442
443
|
E(e, (a) => {
|
|
443
444
|
s.data = g(a);
|
|
444
|
-
});
|
|
445
|
+
}, { flush: "sync" });
|
|
445
446
|
const o = he(s, t), i = ie(s, o), h = ne(i), v = () => {
|
|
446
447
|
r.value = g(e), o.reset(), i.fields.value.forEach(
|
|
447
448
|
(a) => a.reset()
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ export function useForm<T extends FormDataDefault>(options: UseFormOptions<T>) {
|
|
|
28
28
|
|
|
29
29
|
watch(initialData, (newValue) => {
|
|
30
30
|
state.data = cloneRefValue(newValue)
|
|
31
|
-
})
|
|
31
|
+
}, { flush: 'sync' })
|
|
32
32
|
|
|
33
33
|
const validationState = useValidation(state, options)
|
|
34
34
|
const fieldRegistry = useFieldRegistry(state, validationState)
|
package/tests/useForm.test.ts
CHANGED
|
@@ -290,4 +290,37 @@ describe('useForm', () => {
|
|
|
290
290
|
|
|
291
291
|
expect(form.fields.value.length).toBe(0)
|
|
292
292
|
})
|
|
293
|
+
|
|
294
|
+
it('it should take over the new initial data from the form', { timeout: 500 }, async () => {
|
|
295
|
+
const initialData = ref({
|
|
296
|
+
name: 'foo',
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const form = useForm({
|
|
300
|
+
initialData,
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
const nameField = form.getField('name')
|
|
304
|
+
|
|
305
|
+
expect(form.isDirty.value).toBe(false)
|
|
306
|
+
expect(nameField.dirty.value).toBe(false)
|
|
307
|
+
|
|
308
|
+
nameField.setData('modified')
|
|
309
|
+
|
|
310
|
+
expect(form.isDirty.value).toBe(true)
|
|
311
|
+
expect(nameField.dirty.value).toBe(true)
|
|
312
|
+
|
|
313
|
+
initialData.value = {
|
|
314
|
+
name: 'bar',
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
expect(form.initialData.value.name).toBe('bar')
|
|
318
|
+
expect(nameField.initialValue.value).toBe('bar')
|
|
319
|
+
expect(nameField.data.value).toBe('bar')
|
|
320
|
+
|
|
321
|
+
nameField.setInitialData('another')
|
|
322
|
+
|
|
323
|
+
expect(nameField.initialValue.value).toBe('another')
|
|
324
|
+
expect(nameField.data.value).toBe('another')
|
|
325
|
+
})
|
|
293
326
|
})
|