@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.
@@ -9,7 +9,7 @@ const handle_fieldtype_click = (ft) => {
9
9
  };
10
10
  </script>
11
11
 
12
- {#if show_toggle}
12
+ {#if show_toggle || !is_true_field}
13
13
  <div
14
14
  class="ml-auto flex h-fit w-fit flex-row items-center gap-0.5 rounded bg-gray-300 p-0.5 text-xs"
15
15
  >
@@ -1,10 +1,9 @@
1
- <script>import { set } from "lodash-es";
2
- import { getContext, setContext } from "svelte";
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
- const show_toggle = getContext("show_field_expr_toggle") ?? false;
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stubber/form-fields",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "An automatic form builder based on field specifications",
5
5
  "keywords": [
6
6
  "components",