@stubber/form-fields 2.0.3 → 2.0.5
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { setContext } from "svelte";
|
|
2
|
+
import { get as getStoreValue, writable } from "svelte/store";
|
|
2
3
|
import FormField from "./form-field.svelte";
|
|
3
4
|
import { build_fields } from "./utils";
|
|
4
5
|
import { validate_field } from "./validations/validate_field";
|
|
5
|
-
import { setContext } from "svelte";
|
|
6
6
|
export let initial_form;
|
|
7
7
|
export let form;
|
|
8
8
|
export let attachments = writable([]);
|
|
@@ -10,12 +10,7 @@ export let dependencies = void 0;
|
|
|
10
10
|
export let form_valid = false;
|
|
11
11
|
export let dynamic_field_type = false;
|
|
12
12
|
setContext("dynamic_field_type", dynamic_field_type);
|
|
13
|
-
|
|
14
|
-
form.update((data) => {
|
|
15
|
-
return { ...data, ...initial_form.data };
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const fields = build_fields(form, attachments, dependencies, initial_form.spec.fields);
|
|
13
|
+
let fields = [];
|
|
19
14
|
let form_errors = {};
|
|
20
15
|
$: validate_form($form);
|
|
21
16
|
const validate_form = async (_) => {
|
|
@@ -29,6 +24,16 @@ const validate_form = async (_) => {
|
|
|
29
24
|
form_errors = { ...form_errors };
|
|
30
25
|
form_valid = Object.keys(form_errors).length === 0;
|
|
31
26
|
};
|
|
27
|
+
$: rebuild_fields(initial_form, form);
|
|
28
|
+
const rebuild_fields = (initial_form2, form2) => {
|
|
29
|
+
if (initial_form2.data) {
|
|
30
|
+
form2.update((data) => {
|
|
31
|
+
return { ...data, ...initial_form2.data };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
console.log("rebuilding fields");
|
|
35
|
+
fields = build_fields(form2, attachments, dependencies, initial_form2.spec.fields);
|
|
36
|
+
};
|
|
32
37
|
</script>
|
|
33
38
|
|
|
34
39
|
<div class="flex flex-col gap-y-2">
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import { type Writable } from "svelte/store";
|
|
3
|
-
import type { IFormDependencies, IInitialForm } from "./interfaces";
|
|
4
3
|
import type { UploadedFile } from "./fileserver";
|
|
4
|
+
import type { IFormDependencies, IInitialForm } from "./interfaces";
|
|
5
5
|
declare const __propDef: {
|
|
6
6
|
props: {
|
|
7
7
|
initial_form: IInitialForm;
|
|
@@ -76,7 +76,16 @@ export const fields = {
|
|
|
76
76
|
screenrecorder: ScreenrecorderField,
|
|
77
77
|
code: CodeField,
|
|
78
78
|
};
|
|
79
|
-
const string_fields = [
|
|
79
|
+
const string_fields = [
|
|
80
|
+
"text",
|
|
81
|
+
"email",
|
|
82
|
+
"telephone",
|
|
83
|
+
"smart_text",
|
|
84
|
+
"note",
|
|
85
|
+
"code",
|
|
86
|
+
"date",
|
|
87
|
+
"datetime",
|
|
88
|
+
];
|
|
80
89
|
export const final_field_type = (f, allow_dynamic_switching) => {
|
|
81
90
|
if (!allow_dynamic_switching) {
|
|
82
91
|
return f.fieldtype;
|