mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
* chore: add license-header * chore: add precommit * chore: add license header * fix: only js & shell style
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
/**
|
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
import { FormRenderProps, FormMeta, ValidateTrigger } from '@flowgram.ai/fixed-layout-editor';
|
|
|
|
import { FlowNodeJSON } from '../../typings';
|
|
import { FormHeader, FormContent, FormInputs, FormOutputs } from '../../form-components';
|
|
|
|
export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => (
|
|
<>
|
|
<FormHeader />
|
|
<FormContent>
|
|
<FormInputs />
|
|
<FormOutputs />
|
|
</FormContent>
|
|
</>
|
|
);
|
|
|
|
export const formMeta: FormMeta<FlowNodeJSON['data']> = {
|
|
render: renderForm,
|
|
validateTrigger: ValidateTrigger.onChange,
|
|
validate: {
|
|
'inputsValues.*': ({ value, context, formValues, name }) => {
|
|
const valuePropetyKey = name.replace(/^inputsValues\./, '');
|
|
const required = formValues.inputs?.required || [];
|
|
if (
|
|
required.includes(valuePropetyKey) &&
|
|
(value === '' || value === undefined || value?.content === '')
|
|
) {
|
|
return `${valuePropetyKey} is required`;
|
|
}
|
|
return undefined;
|
|
},
|
|
},
|
|
};
|