baidu / baidu/amis

给自定义组件setValue无效

Open
#9,101 12 comments 0 reactions 1 assignee Claimed by @allenve View on GitHub
need confirm
Dominant language
TypeScript
Stars
18.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

#### 描述问题:

下拉框更改值以后,用selectedItems中字段给其他组件赋值,amis自带组件能赋值成功,但是自定义组件赋值失败,而且会导致下拉框显示问题,自定义组件使用FormItem注解

#### 截图或视频:

![2023-12-11_15-37-30](https://github.com/baidu/amis/assets/21698755/9f204bc0-b9b5-48b7-b0e5-ac3199bba5a1)

#### 如何复现(请务必完整填写下面内容):

1. 你是如何使用 amis 的?
`npm`

2. amis 版本是什么?
```
"amis": "^3.4.1",
"amis-formula": "^3.4.1",
```

3. 粘贴有问题的完整 `amis schema` 代码:
```
// schema代码
{
type: 'page',
body: [
{
type: 'form',
body: [
{
type: 'select',
label: '下拉框',
name: 'select',
id: 'select',
multiple: false,
options: [
{
label: '测试内容',
value: '1',
default_amount: '100',
custom_attach_file: [
{ name: '文件1', id: '1', size: 10000, url: 'http://www.baidu.com' },
],
custom_input_value: 'custom_input_value',
},
],
onEvent: {
change: {
weight: 0,
actions: [
{
componentId: 'default_amount',
ignoreError: false,
actionType: 'setValue',
args: {
value: '${event.data.selectedItems.default_amount}',
},
},
{
componentId: 'custom_attach_file',
ignoreError: false,
actionType: 'setValue',
args: {
value: '${event.data.selectedItems.custom_attach_file}',
},
},
{
componentId: 'custom_input_value',
ignoreError: false,
actionType: 'setValue',
args: {
value: '${event.data.selectedItems.custom_input_value}',
},
},
],
},
},
},
{
type: 'custom-input',
label: '自定义input',
name: 'custom_input_value',
id: 'custom_input_value',
keyboard: true,
},
{
type: 'custom-upload',
label: '自定义上传',
name: 'custom_attach_file',
id: 'custom_attach_file',
disabled: false,
},
{
type: 'input-number',
label: '默认组件',
name: 'default_amount',
id: 'default_amount',
keyboard: true,
step: 1,
static: true,
},
],
actions: [],
},
],
}

// custom-input代码
import { FormItem } from 'amis';
import { FormItemProps } from 'amis';
import React from 'react';
import { Input } from 'antd';

export type CustomInputProps = FormItemProps;

export default FormItem({
type: 'custom-input',
// strictMode: false,
autoVar: true,
})(
class CustomInput extends React.Component {
static defaultProps = {};

render() {
const { value, onChange, placeholder, maxLength, ...rest } = this.props;
function onValueChange(event) {
onChange(event.target.value);
}
return (




);
}
} as any,
);

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.