diff --git a/src/renderers/Form/Options.tsx b/src/renderers/Form/Options.tsx index 7625f8409..76a8b1063 100644 --- a/src/renderers/Form/Options.tsx +++ b/src/renderers/Form/Options.tsx @@ -106,10 +106,10 @@ export const detectProps = itemDetectProps.concat([ 'extractValue' ]); -export function registerOptionsControl(config: OptionsConfig) { - const Control = config.component; - - class FormOptionsItem extends React.Component { +export function asOptionsControl( + Control: React.ComponentType +) { + return class FormOptionsItem extends React.Component { static displayName = `OptionsControl(${config.type})`; static defaultProps = { delimiter: ',', @@ -826,12 +826,16 @@ export function registerOptionsControl(config: OptionsConfig) { /> ); } - } + }; +} + +export function registerOptionsControl(config: OptionsConfig) { + const Control = config.component; return registerFormItem({ ...(config as FormItemBasicConfig), strictMode: false, - component: FormOptionsItem + component: asOptionsControl(Control) }); } diff --git a/src/renderers/Form/index.tsx b/src/renderers/Form/index.tsx index 176d7ee35..cd563cf3d 100644 --- a/src/renderers/Form/index.tsx +++ b/src/renderers/Form/index.tsx @@ -34,6 +34,7 @@ import {LazyComponent} from '../../components'; import {isAlive} from 'mobx-state-tree'; import {asFormItem} from './Item'; import {SimpleMap} from '../../utils/SimpleMap'; +import {asOptionsControl} from './Options'; export type FormGroup = FormSchema & { title?: string; className?: string; @@ -1026,7 +1027,11 @@ export default class Form extends React.Component { control.options || { strictMode: false } - )(control.component); + )( + control.options || control.source + ? asOptionsControl(control.component) + : control.component + ); this.componentCache.set(control.component, cache); control.component = cache; }