Ivan Galakhov 4 лет назад
Родитель
Сommit
a5fb830681

+ 10 - 10
dashboard/src/components/form-refactor/field-components/Checkbox.tsx

@@ -13,17 +13,17 @@ const Checkbox: React.FC<Props> = ({
   required,
   variable,
   isReadOnly,
+  settings,
 }) => {
-  const { state, variables, setVars } = useFormField<CheckboxFieldState>(
-    id,
-    {
-      initState: {},
-      initValidation: {
-        validated: !required,
-      },
-      initVars: {},
-    }
-  );
+  const { state, variables, setVars } = useFormField<CheckboxFieldState>(id, {
+    initState: {},
+    initValidation: {
+      validated: !required,
+    },
+    initVars: {
+      [variable]: !!settings?.default,
+    },
+  });
 
   if (state == undefined) {
     return <></>;

+ 9 - 8
dashboard/src/components/form-refactor/types.ts

@@ -25,24 +25,25 @@ export interface SubtitleField extends GenericField {
   label: string;
 }
 
-export interface StringInputFieldSettings {
-  type?: "text"|"password"|"number";
-  unit?: string;
-  omitUnitFromValue?: boolean;
-  default: string|number;
-}
-
 export interface InputField extends GenericInputField {
   type: "input";
   label?: string;
   placeholder?: string;
   info?: string;
-  settings?: StringInputFieldSettings;
+  settings?: {
+    type?: "text"|"password"|"number";
+    unit?: string;
+    omitUnitFromValue?: boolean;
+    default: string|number;
+  };
 }
 
 export interface CheckboxField extends GenericInputField {
   type: "checkbox";
   label?: string;
+  settings?: {
+    default: boolean
+  }
 }
 
 export interface KeyValueArrayField extends GenericInputField {