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

AutoComplete选中回显了value #32575

Closed
1 task
theDoinb opened this issue Oct 20, 2021 · 5 comments
Closed
1 task

AutoComplete选中回显了value #32575

theDoinb opened this issue Oct 20, 2021 · 5 comments
Labels
🤔 Need Reproduce We cannot reproduce your problem

Comments

@theDoinb
Copy link

theDoinb commented Oct 20, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

如上链接

What is expected?

选中某个客户时,回显 label 值

What is actually happening?

选中某个客户时,回显 value 值

Environment Info
antd 4.16.13
React 16.8.0
System win10
Browser chrome

这个是设计就是这样吗?
像现在好几个需求,要先库里搜索某个客户之类,然后将ID代入参数中。
这种回显让我比较头痛,像客户或者某些数据确实有重复的,用名称没法识别是哪个
如果设计是这样,能否加入类似 showLabelProps 去指定要显示的内容呢

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label Oct 20, 2021
@github-actions
Copy link
Contributor

Hello @theDoinb. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @theDoinb, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

@theDoinb
Copy link
Author

Edit on CodeSandbox

@zombieJ
Copy link
Member

zombieJ commented Oct 20, 2021

设计如此,AutoComplete 是带提示的输入框,所以你 value 是什么它的值就是什么。如果需要展示 label 应该用 Select。

ref: https://ant.design/components/auto-complete-cn/#%E4%BD%95%E6%97%B6%E4%BD%BF%E7%94%A8

@zombieJ zombieJ closed this as completed Oct 20, 2021
@kangyana
Copy link

kangyana commented Dec 29, 2021

Try this one.
The onChange function passes 'key'.

const CustomAutoComplete = (props) => {
  const { value, options, onChange, ...restProps } = props;

  const handleSelect = (_value, _option) => {
    onChange(_option.key);
  };

  const realOptions = options?.map(v => ({ ...v, key: v.value }));

  return (
    <AutoComplete
      options={realOptions}
      onSelect={handleSelect}
      {...restProps}
    />
  )
}

@dadanliu
Copy link

设计如此,AutoComplete 是带提示的输入框,所以你 value 是什么它的值就是什么。如果需要展示 label 应该用 Select。

ref: https://ant.design/components/auto-complete-cn/#%E4%BD%95%E6%97%B6%E4%BD%BF%E7%94%A8

value 是什么 它就是什么没错,那我如果只想回填一部分呢,另一部分是去跟其他表单里的值做交互;在这种情况下是不是现在的设计方案就不灵活,现在的方案是只能满足填充自己的值,做联动的话就不太行了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

5 participants