Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options 选择器表单项多选 multiple在联动时存在BUG,标签没被清除 #11210

Open
tmd-user opened this issue Nov 16, 2024 · 8 comments
Labels
bug Something isn't working need confirm

Comments

@tmd-user
Copy link

描述问题:

在x'z选择多选的时候,由于options下我添加了hiddenOn来控制是否显示的,当我选择好数据时,再修改联动的组件,是靠这个组件来控制options的,这时由于条件生效,多项的部分就被隐藏了,但是BUG就来了标签没被清除,而是变为了预设值

截图或视频:

type这个开始默认为1,select这时就是可选择1、4的,选择完后再重新选择type为4,这时候options就没可用的数据了
image

下面这个更加诡异,当手动清除完标签后,下拉选项直接显示被隐藏的预设值
image

开始我是想使用动作去对表单重置的,这个效果有一点点好用。但是,如果是通过API方式获取表单数据的时候,这个方法就不可行了

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

  1. 你是如何使用 amis 的?
    sdk

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在
    6.9.0

  3. 粘贴有问题的完整 amis schema 代码:

```javascript
{
  "type": "page",
  "title": "Hello world",
  "body": [
    {
      "type": "button-group-select",
      "label": "类型",
      "inline": false,
      "options": [
        {
          "label": "个人",
          "value": "1"
        },
        {
          "label": "个体工商户",
          "value": "2"
        },
        {
          "label": "企业",
          "value": "3"
        },
        {
          "label": "其他",
          "value": "4"
        }
      ],
      "placeholder": "请选择主体进件类型",
      "required": true,
      "value": "1",
      "name": "type",
      "id": "type",
      "multiple": false
    },
    {
      "type": "select",
      "label": "平台",
      "multiple": true,
      "inline": false,
      "options": [
        {
          "value": 4,
          "label": "邮政",
          "hiddenOn": "${type != '1' && type != '2'}"
        },
        {
          "value": 3,
          "label": "农业",
          "hiddenOn": "${type != '2' && type != '3'}"
        },
        {
          "label": "中国",
          "value": "2",
          "hiddenOn": "${type != '2'}"
        },
        {
          "label": "建设",
          "value": "1",
          "hiddenOn": "${type != '1' && type != '3'}"
        }
      ],
      "placeholder": "请选择申请渠道平台",
      "joinValues": true,
      "required": true,
      "name": "platform",
      "id": "platform",
      "checkAll": false
    }
  ],
  "id": "u:81dc27953f1c",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  }
}

5. 操作步骤
在https://aisuda.github.io/amis-editor-demo/#/edit/0上测试的
@github-actions github-actions bot added the bug Something isn't working label Nov 16, 2024
Copy link

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

@tmd-user
Copy link
Author

@2betop @TeCHiScy @luckyufei @weien601 解决一下

@tmd-user
Copy link
Author

@2betop @TeCHiScy @luckyufei @weien601 使用source远程获取时也是一样,当我已经有选择的情况下,通过动作对此组件重新获取数据时,接口返回数据是空的,但是标签依然存在,点击下拉是提示没内容的,但是手动删除后,就自动给添加了一个标签的数据存储到了options里面

@tmd-user
Copy link
Author

目前解决办法是,在type这个组件中添加一个清除事件

@tmd-user
Copy link
Author

但是还有一个更加难处理的BUG,表单数据是从接口获取的,在这种情况下type这个组件不管你怎么去添加什么事件都没有,标签一直显示接口获取到的,手动清除后,在type这个组件值变化后platform的又恢复接口获取的

@lhtuling
Copy link

这个bug之前反馈过 ,我还提过pr,不过不规范, 后续官方估计会修改,先用自己方法搞定吧~~

Amis低代码前端框架交流群【QQ1群】:717791727
Amis低代码前端框架交流群【QQ2群】:721182449

@rubbishmaker
Copy link

rubbishmaker commented Nov 24, 2024

image
amis\packages\amis\src\renderers\Form\Select.tsx文件下这行代码应该需要考虑你说的这个情况

@jinmingpang
Copy link
Contributor

你的核心需求是,第2个选项框的options, 是根据第1个,选项选的值动态切换的,可以换一个联动思路绕一绕。

// 注册一个 filter ,根据第1个选项框,选项值,来设置 第2个选项框的 options。具体逻辑可以任意
registerFilter('setSelect2Options', (select1) => {
  if (select1 === 'a') {
    return [{
      label: 'a1',
      value: 'a1'
    }, {
        label: 'a2',
        value: 'a2'
    }]
  }
  if (select1 === 'b') {
    return [{
      label: 'b1',
      value: 'b1'
    }, {
      label: 'b2',
      value: 'b2'
    }]
  }
  if (select1 === 'c') {
    return [{
      label: 'c1',
      value: 'c1'
    }, {
      label: 'c2',
      value: 'c2'
    }]
  }
})

// 具体配置的JSON
 {
  "type": "page",
  "body": {
    type: 'form',
    debug: true,
    "initApi": {
     // 模拟API,同时返回 2个选项框的默认值
      url: "/api/amis-mock/mock2/form/initData",
      adaptor: () => {
        return {
          select1: 'a',
          select2: 'a1'
        }
      }
    },
    body: [{
      "type": "button-group-select",
      label: 'select1',
      name: 'select1',
      "options": [
        {
          type: 'button',
          label: 'a',
          value: 'a'
        },
        {
          type: 'button',
          label: 'b',
          value: 'b'
        },
        {
          type: 'button',
          label: 'c',
          value: 'c'
        }
      ],
      // 第1个选项框的值发生变更,自动设置第2个选项框的值
      autoFill: {
        select2Options: '${value|setSelect2Options}'
      },
     // 第1个选项框的值发生切换,将第2个框的值删除 
      onEvent: {
        change: {
          actions: [{
            actionType: 'setValue',
            componentId: 'select2',
            args: {
              value: ''
            }
          }]
        }
      }
    }
    , {
      label: 'select2',
      name: 'select2',
      id: 'select2',
      type: 'select',
      // 第2个选项框的值,来自于 动态设置的值
      source: '${select2Options}',
    }],
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need confirm
Projects
None yet
Development

No branches or pull requests

4 participants