question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to set default value to the AutoCompleteInput

See original GitHub issue

  let cats = [
    { id: 'CAT_1', label: 'Kitty 1' },
    { id: 'CAT_2', label: 'Kitty 2'},
  ];

  return
  <AutoComplete openOnFocus suggestWhenEmpty rollNavigation>
    <AutoCompleteInput variant="ghost" bgColor="transparent" />

    <AutoCompleteList fontStyle="normal">
      {cats.map((cat) => (
        <AutoCompleteItem
          key={cat.id}
          value={cat.label}
          textTransform="capitalize"
        >
          {cat.label}
        </AutoCompleteItem>
      ))}
    </AutoCompleteList>
  </AutoComplete>
}

Package version “@choc-ui/chakra-autocomplete”: “^4.3.3”,

I want the default value in the input box to be set to “Kitty 1” whenever the page loads. With the above code, the input box is empty on page load which seems like the expected behaviour.

  • I tried setting defaultValue to the <AutoCompleteInput> component but it doesn’t do anything.
  • I tried setting value to the <AutoCompleteInput> component. It worked but whenever I focus on the input box first time and click outside the <AutoCompleteList>, the value disappears.

What is the right way to go about it?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anubra266commented, Aug 2, 2021

Yeah…that would work, but I should handle it internally. I’ll work on this, in a moment

1reaction
rahulsuresh-gitcommented, Aug 2, 2021

I’ll try this and get back. Thanks for the quick reply.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autocomplete - How can I set a default value? - Stack Overflow
The component have a dataSource , and I'd like to load the page with a specific item already selected(e.g. fill the text field...
Read more >
enableGetChoices prevents setting defaultValue on ... - GitHub
What you were expecting: For a AutocompleteInput with a ReferenceInput as a parent to receive the prop "defaultValues" and make the required ...
Read more >
How to turn off form autocompletion - Web security | MDN
This article explains how a website can disable autocomplete for form fields. By default, browsers remember information that the user ...
Read more >
How to set default value with next line in NowMobile input ...
i've tried using \n, <br>, and br(). It seems not able to format it. Please see the screen shot in the attachments. In...
Read more >
How to Use The Autocomplete Component in Material-UI
Set up; Render the Autocomplete component; Props; Handle the value; Additional props; Conclusion ... We will set the default value to null.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found