yury-dymov / react-autocomplete-input

Autocomplete input field for React
https://yury-dymov.github.io/react-autocomplete-input/
MIT License
199 stars 65 forks source link

[Help] Use for transliteration #49

Closed burhanuday closed 4 years ago

burhanuday commented 4 years ago

First of all, thanks for this amazing library

I am trying to use this component for transliteration. Meaning that i want my users to type in English and am using an api to fetch Hindi suggestions. Since the match between these characters will always be false, how do i show suggestions when text is typed in English but my suggestions are in Hindi

Any help is appreciated!

yury-dymov commented 4 years ago

You would need to provide custom value for ‘regex’ prop

burhanuday commented 4 years ago

Hello This is how i am using the component

 <TextInput
        trigger=""
        options={options}
        onRequestOptions={getSuggestions}
        placeholder="type here"
        requestOnlyIfNoOptions={false}
        regex=".+"
      />

I am making an api request in getSuggestions and so it is an async function When i write a, the options i recieve from the api are [ "ा", "आ", "अ", "े", "ए" ] I have tried both .* and .+ for the regex prop but i dont get any suggestions

It works fine when i use English options like in the demo

yury-dymov commented 4 years ago

This is likely a js regex problem, you would probably need an external library, which handles international regex.

burhanuday commented 4 years ago

This is how i did it for transliteration

<TextInput
      trigger=""
      value={value}
      onChange={(val) => {
        onChange(val); //local state
        setOptions([]); // local state
      }}
      options={options}
      onRequestOptions={getSuggestions} // this is an async function that fetches data from an api
      requestOnlyIfNoOptions={false}
      />

Then in the component, on line 151 you will have to make this change

const options = providedOptions;