(props: P) => React.PureComponent>;
data?: T;
key?: string;
extendKeys?: string[];
@@ -116,235 +117,36 @@ export default class CustomForm extends Component, State> {
public renderFormComponent(config: DTGComponentPropertySchema) {
const { formValues, helpMsg } = this.state;
const uiProps = config['ui:props'] || {};
- if (config['ui:type'] === 'input') {
- return (
- {
- const value = e.target.value;
- formValues[config.name] = (config as StringDataSchema).transform?.includes('trim') ? value.trim() : value;
- this.setState({ formValues }, () => { this.changeData(); });
- if (config.validate) {
- const res = config.validate(value);
- (res instanceof Promise ? res : Promise.resolve(res))
- .then((msg) => {
- helpMsg[config.name] = msg || '';
- this.setState({ helpMsg });
- return msg;
- })
- .catch((error) => { throw error; });
- }
- }}
- />
- );
- }
- if (config['ui:type'] === 'text') {
- return (
- {
- const value = e.target.value;
- formValues[config.name] = (config as StringDataSchema).transform?.includes('trim') ? value.trim() : value;
- this.setState({ formValues }, () => { this.changeData(); });
- if (config.validate) {
- const res = config.validate(value);
- (res instanceof Promise ? res : Promise.resolve(res))
- .then((msg) => {
- helpMsg[config.name] = msg || '';
- this.setState({ helpMsg });
- return msg;
- })
- .catch((error) => { throw error; });
- }
- }}
- />
- );
- }
- if (config['ui:type'] === 'auto-complete') {
- return (
- {
- formValues[config.name] = (config as StringDataSchema).transform?.includes('trim') ? value.trim() : value;
- this.setState({ formValues }, () => { this.changeData(); });
- if (config.validate) {
- const res = config.validate(value);
- (res instanceof Promise ? res : Promise.resolve(res))
- .then((msg) => {
- helpMsg[config.name] = msg || '';
- this.setState({ helpMsg });
- return msg;
- })
- .catch((error) => { throw error; });
- }
- }}
- />
- );
- }
- if (config['ui:type'] === 'switch') {
- const checkedValue = uiProps.checkedValue ? formValues[config.name] === uiProps.checkedValue : formValues[config.name] as boolean;
- return (
- {
- let value: boolean | string | number = checked;
- if (uiProps.checkedValue && uiProps.unCheckedValue) {
- value = checked ? uiProps.checkedValue as string | number : uiProps.unCheckedValue as string | number;
- }
- formValues[config.name] = value;
- this.setState({ formValues }, () => { this.changeData(); });
- }}
- />
- );
- }
- if (config['ui:type'] === 'number') {
+ if (config['ui:type'] === 'render-html') {
return (
- {
- formValues[config.name] = checked;
- this.setState({ formValues }, () => { this.changeData(); });
- }}
- />
+
);
}
- if (config['ui:type'] === 'checkbox') {
+ if (config['ui:type'].startsWith('custom::')) {
+ const ComponentName = config['ui:type'].replace('custom::', '');
+ const CustomComponent = this.props.extraComponents?.[ComponentName] || config['ui:externalComponent'];
return (
- | Record[]}
onChange={(value) => {
formValues[config.name] = value;
- this.setState({ formValues }, () => { this.changeData(); });
+ this.setState({ formValues }, () => {
+ this.changeData();
+ });
}}
- >
- { (uiProps.options as CheckboxGroupProps['options'])?.map((option, i) => {
- if (typeof option === 'string') {
- option = { label: option, value: option };
- }
- return (
- { option.label }
- );
- }) }
-
- );
- }
- if (config['ui:type'] === 'radio') {
- return (
- {
- formValues[config.name] = e.target.value;
- this.setState({ formValues }, () => { this.changeData(); });
+ onValidate={(msg: string) => {
+ helpMsg[config.name] = msg || '';
+ this.setState({ helpMsg });
}}
- >
- { (uiProps.options as CheckboxGroupProps['options'])?.map((option, i) => {
- if (typeof option === 'string') {
- option = { label: option, value: option };
- }
- return ({ option.label });
- }) }
-
- );
- }
- if (config['ui:type'] === 'select') {
- const formattedValue = (uiProps.mode === 'multiple' || uiProps.mode === 'tags') && !Array.isArray(formValues[config.name]) ? [formValues[config.name]] : formValues[config.name];
- return (
-