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

How to clear the selected value Programmatically ? #94

Open
YuvantBesre opened this issue Nov 26, 2022 · 9 comments
Open

How to clear the selected value Programmatically ? #94

YuvantBesre opened this issue Nov 26, 2022 · 9 comments

Comments

@YuvantBesre
Copy link

How to clear the value of the input box with the help of code ? Isn't there any function exposed ? There is nothing in the docs as well.

@YuvantBesre YuvantBesre changed the title How to clear the value Programmatically ? How to clear the selected value Programmatically ? Nov 26, 2022
@harryc9
Copy link

harryc9 commented Feb 14, 2023

+1

Can't set the input value to an empty string via JavaScript, weird 😅

@ConsoliNiccolo
Copy link

+1,

Any news ?

@TX1999-pro
Copy link

+1
How could we clear the text if the user pressed esc, or clicked a button of reset? I tried the HTML onChange attriubte which doesn't work with this search bar component.

I will really appreciate if there is a workaround or anyone explain how the text input displayed within the search bar is accessed.

@Junder729
Copy link

i need help, any news?

@Junder729
Copy link

Solution:
const handleClick = () => {
const divElements = document.querySelectorAll('.clear-icon');
divElements.forEach((divElement) => {
divElement.click();
});
}
Create function for closed de select 😄

@sabotage69
Copy link

Solution: const handleClick = () => { const divElements = document.querySelectorAll('.clear-icon'); divElements.forEach((divElement) => { divElement.click(); }); } Create function for closed de select 😄

Can you please provide more details on your implementation? I too can choose .clear-icon through querySelector but clicking it inside of handleOnSelect seemingly does nothing. Already wasted 2 hours on this so greatly appreciate your response

@mustapha-ghlissi
Copy link

@Junder729 what if .clear-icon is disabled ? is other words isn't displayed !

Did you solution work for this case too ?

@arimourao
Copy link

Good that the mantainers didn't even bother to help :/

@cellis
Copy link

cellis commented Aug 6, 2024

Like this:

const [inputSearchString, setInputSearchString] = useState('' as string);
//...
<ReactSearchAutocomplete
          onSelect={() => {
          //...select logic here
          setInputSearchString('')
          }
          onSearch={(str) => {
            setInputSearchString(str);
          }}
          inputSearchString={inputSearchString}/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants