@stubber/form-fields 1.7.3 → 1.7.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,10 +1,9 @@
|
|
|
1
|
-
<script>import { set } from "lodash-es";
|
|
2
|
-
import {
|
|
1
|
+
<script>import { get, set } from "lodash-es";
|
|
2
|
+
import { setContext } from "svelte";
|
|
3
3
|
import { writable } from "svelte/store";
|
|
4
4
|
import { component_for, final_field_type } from "./interfaces";
|
|
5
5
|
export let fieldStore;
|
|
6
|
-
|
|
7
|
-
let fieldtype = final_field_type($fieldStore, show_toggle);
|
|
6
|
+
let fieldtype = final_field_type($fieldStore, true);
|
|
8
7
|
let component = component_for(fieldtype);
|
|
9
8
|
const field_component_store = writable({ fieldtype });
|
|
10
9
|
setContext("field_component", field_component_store);
|
|
@@ -17,6 +16,12 @@ const handle_field_type_change = (new_fieldtype) => {
|
|
|
17
16
|
const new_value = new_fieldtype == "smart_text" ? typeof $fieldStore.value === "string" ? $fieldStore.value : "" : new_fieldtype == "checkbox" ? false : new_fieldtype == "number" ? 0 : new_fieldtype == "arraybuilder" ? [] : new_fieldtype == "section" || new_fieldtype == "objectbuilder" ? {} : null;
|
|
18
17
|
$fieldStore.formStore.update((form) => {
|
|
19
18
|
set(form, $fieldStore.data_path, new_value);
|
|
19
|
+
if (get(form, `${$fieldStore.data_path}_details`)) {
|
|
20
|
+
delete form[`${$fieldStore.data_path}_details`];
|
|
21
|
+
}
|
|
22
|
+
if (get(form, `${$fieldStore.data_path}_label`)) {
|
|
23
|
+
delete form[`${$fieldStore.data_path}_label`];
|
|
24
|
+
}
|
|
20
25
|
return form;
|
|
21
26
|
});
|
|
22
27
|
component = component_for(new_fieldtype);
|
|
@@ -81,6 +81,13 @@ export const final_field_type = (f, allow_dynamic_switching) => {
|
|
|
81
81
|
if (!allow_dynamic_switching) {
|
|
82
82
|
return f.fieldtype;
|
|
83
83
|
}
|
|
84
|
+
if (f.fieldtype === "select") {
|
|
85
|
+
const options = f.params?.options || [];
|
|
86
|
+
const has_value_in_options = options.some((opt) => opt.value === f.value);
|
|
87
|
+
if (has_value_in_options) {
|
|
88
|
+
return "select";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
84
91
|
const is_string = typeof f.value === "string";
|
|
85
92
|
// if the initial value is a string
|
|
86
93
|
// but this field isn't typically a string field,
|