mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
fix: 单选选项值包含逗号时获取选项错误问题 (#6258)
* fix: 单选选项值包含逗号时获取选项错误问题 * 加个单测 * 单测问题 * 在WrapControl 中使渲染器默认 multiple 生效 * 修改
This commit is contained in:
parent
9b12189cb7
commit
3e5bc113ab
@ -18,6 +18,7 @@ icon:
|
||||
"label": "默认",
|
||||
"type": "transfer",
|
||||
"name": "transfer",
|
||||
"value": "zhugeliang,libai",
|
||||
"options": [
|
||||
{
|
||||
"label": "诸葛亮",
|
||||
|
@ -31,6 +31,7 @@ import {withRootStore} from '../WithRootStore';
|
||||
import {FormBaseControl, FormItemWrap} from './Item';
|
||||
import {Api} from '../types';
|
||||
import {TableStore} from '../store/table';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
export interface ControlOutterProps extends RendererProps {
|
||||
formStore?: IFormStore;
|
||||
@ -181,6 +182,11 @@ export function wrapControl<
|
||||
// @issue 打算干掉这个
|
||||
formItem?.addSubFormItem(model);
|
||||
model.config({
|
||||
// 理论上需要将渲染器的 defaultProps 全部生效,此处保险起见先只处理 multiple
|
||||
...pick(
|
||||
{...ComposedComponent.defaultProps, ...this.props.$schema},
|
||||
['multiple']
|
||||
),
|
||||
id,
|
||||
type,
|
||||
required,
|
||||
@ -189,7 +195,6 @@ export function wrapControl<
|
||||
isValueSchemaExp: isExpression(value),
|
||||
rules: validations,
|
||||
messages: validationErrors,
|
||||
multiple,
|
||||
delimiter,
|
||||
valueField,
|
||||
labelField,
|
||||
|
@ -164,7 +164,8 @@ export const FormItemStore = StoreNode.named('FormItemStore')
|
||||
? nodeValueArray
|
||||
: Array.isArray(value)
|
||||
? value
|
||||
: typeof value === 'string'
|
||||
: // 单选时不应该分割
|
||||
typeof value === 'string' && self.multiple
|
||||
? value.split(self.delimiter || ',')
|
||||
: [value];
|
||||
const selected = valueArray.map(item =>
|
||||
|
@ -817,3 +817,45 @@ test('Renderer:select associated mode with virtual', async () => {
|
||||
|
||||
expect(container).toMatchSnapshot('');
|
||||
});
|
||||
|
||||
test('Renderer:select value contains delimiter when single', async () => {
|
||||
const {container} = render(
|
||||
amisRender({
|
||||
type: 'page',
|
||||
body: {
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
label: '单选不分割',
|
||||
type: 'select',
|
||||
name: 'select',
|
||||
value: 'a,b',
|
||||
options: [
|
||||
{
|
||||
label: 'ALabel',
|
||||
value: 'a,b'
|
||||
},
|
||||
{
|
||||
label: 'BLabel',
|
||||
value: 'b'
|
||||
},
|
||||
{
|
||||
label: 'CLabel',
|
||||
value: 'c'
|
||||
},
|
||||
{
|
||||
label: 'DLabel',
|
||||
value: 'd'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
expect(
|
||||
container.querySelector('.cxd-Select-valueWrap .cxd-Select-value')!
|
||||
.innerHTML
|
||||
).toEqual('ALabel');
|
||||
});
|
||||
|
@ -175,6 +175,10 @@ type OptionsControlWithSpinnerProps = OptionsControlProps & SpinnerExtraProps;
|
||||
export class BaseTransferRenderer<
|
||||
T extends OptionsControlWithSpinnerProps = BaseTransferProps
|
||||
> extends React.Component<T> {
|
||||
static defaultProps = {
|
||||
multiple: true
|
||||
};
|
||||
|
||||
tranferRef?: any;
|
||||
|
||||
reload() {
|
||||
|
Loading…
Reference in New Issue
Block a user