I'am using react-native-autocomplete-dropdown package for selecting options fetched from an api. I require that when user type first 6 digits then hyphen(-) automatically should be added after that and user must continue typing after that also .
Like if user types 12151996. then in input box it should look like 121519-96 acoording to requirement user will not type hyphen . it should be automatically added .
link for package : https://www.npmjs.com/package/react-native-autocomplete-dropdown My code :
<AutocompleteDropdown
ref={searchRef}
onFocus={() => {
setactiveCpr(true);
}}
clearOnFocus={false}
onClear={() => {
setactiveCpr(false);
}}
// onBlur={() => {
// setactiveCpr(false);
// }}
// closeOnBlur={true}
controller={controller => {
dropdownController.current = controller;
}}
dataSet={suggestionsList}
onChangeText={text => {
getSuggestions(text);
onChangeTextHandler(text);
text = text + '';
}}
onSelectItem={item => {
item && setSelectedItem(item.id);
item && fullLookUp(item.id);
item && journalHistory(item.id);
item && Laboratoriesvar(item.id);
setSuggestionsList(null);
}}
// debounce={600}
onSubmit={() => {
setactiveCpr(false);
}}
onClear={() => {
setactiveCpr(false);
setSelectedItem(null);
}}
// onSubmit={(e) => onSubmitSearch(e.nativeEvent.text)}
// onOpenSuggestionsList={onOpenSuggestionsList}
loading={loading}
useFilter={false} // prevent rerender twice
textInputProps={{
editable: selectedItem ? false : true,
value: selectedItem,
onChangeText: t => {
searchRef.current.onChangeText = i => {
console.log(i);
};
},
style: {
backgroundColor: theme.inputBg,
color: '#000',
paddingLeft: 13,
fontSize: 14,
},
}}
rightButtonsContainerStyle={{
borderRadius: 25,
right: 8,
height: 30,
top: 5,
alignSelfs: 'center',
backgroundColor: 'transparent',
}}
inputContainerStyle={{
backgroundColor: 'transparent',
}}
suggestionsListContainerStyle={{
backgroundColor: 'white',
zIndex: 300,
}}
renderItem={(item, text) => (
<Text style={{color: '#000', padding: 15}}>
{`${item.id} ${item.title}`}
</Text>
)}
inputHeight={40}
showChevron={false}
/>