diff --git a/packages/velaux-ui/src/components/UISchema/index.tsx b/packages/velaux-ui/src/components/UISchema/index.tsx index 0b601c6e..4a8d7dee 100644 --- a/packages/velaux-ui/src/components/UISchema/index.tsx +++ b/packages/velaux-ui/src/components/UISchema/index.tsx @@ -134,6 +134,7 @@ class UISchema extends Component { if (this.props.registerForm) { this.props.registerForm(this.form); } + this.initFormValues(); this.state = { secretKeys: [], advanced: props.advanced || false, @@ -176,6 +177,32 @@ class UISchema extends Component { }); }; + initFormValues = () => { + // Extract default values from the UI schema + const extractDefaultValues = (uiSchema) => { + const initialValues = {}; + + // Loop through the UI schema and extract default values + uiSchema?.forEach((param) => { + if (param.validate?.defaultValue !== undefined) { + initialValues[param.jsonKey] = param.validate.defaultValue; + } + }); + + return initialValues; + }; + + const defaultValues = extractDefaultValues(this.props.uiSchema); + + // Initialize the form with default values + if (defaultValues) { + const { onChange } = this.props; + if (onChange) { + onChange(defaultValues); + } + } + }; + conditionAllowRender = (conditions?: ParamCondition[]) => { if (!conditions || conditions.length == 0) { return true;