javascript - How to show NoOptionsText only with condition in MaterialUI Autocomplete - Stack Overflow

I have a Material UI autoplete that selects its items based on the 3 letters you type, for example:You

I have a Material UI autoplete that selects its items based on the 3 letters you type, for example:

You want to fetch all the Pedros in your database, then you type "Ped" and it brings you only results that start with "Ped".

The problem is when I click in the auto plete it immediately shows the message "No options" like

And I want it only to show after I typed 3 characters and it did not find any "Ped" in the database like:

I tried to put a condition inside the prop "noOptionsText" but it did not work. Does anyone know how to do it?

EDIT: Without using freeSolo, the option needs to be an object

I have a Material UI autoplete that selects its items based on the 3 letters you type, for example:

You want to fetch all the Pedros in your database, then you type "Ped" and it brings you only results that start with "Ped".

The problem is when I click in the auto plete it immediately shows the message "No options" like

And I want it only to show after I typed 3 characters and it did not find any "Ped" in the database like:

I tried to put a condition inside the prop "noOptionsText" but it did not work. Does anyone know how to do it?

EDIT: Without using freeSolo, the option needs to be an object

Share Improve this question edited Mar 24, 2020 at 15:22 keikai 15.2k10 gold badges55 silver badges72 bronze badges asked Mar 24, 2020 at 14:17 Pedro W. BotelhoPedro W. Botelho 2841 gold badge4 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Okay, I just found a way to answer my question.

There's the prop "open" in Material UI's Autoplete. I just put a condition like:

open={lenght >= 3}

Then it only opens the options when I've typed the first 3 characters, otherwise it won't open. Plus, when I typed the 3 characters and there's no options, it will display the no options text.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744404790a4572576.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信