Replies: 1 comment
-
@meliborn Unfortunately, there is no way to pass just an id. Working with an AsyncSelect, I think you can understand the problem. How will an AsyncSelect know what label to display when the full list of options are not available to lookup that given id? Likely you would want to make an api call to get the formatted option value and set that as the value for the AsyncSelect. Since this would now be a controlled input, you'd want to add to the onChange handler as well. const { cityId } = props;
const [ selected, setSelected ] = useState();
useEffect(() => {
cityId && callApiToGetCityById(cityId).then(resp => {
setSelected({ label: resp.name, value: cityId });
})
}, [ cityId ]);
const onChange = option => {
setSelected(option);
handleOptionChange(option, 'cityEq');
}
return <AsyncUnifySelect
onChange={onChange}
placeholder={t('common:city')}
value={selected}
isClearable
promiseOptions={(search: string): Promise<AutoCompleteRecord[]> =>
promiseOptions(TOWN_AUTOCOMPLETE, 'towns', 'name', search)
}
/> Let me know if you have any further questions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a real-select async input (autocomplete). It looks like this:
As you might see, options comes from API. What I want is to have the ability to set selected option from the URL params. For example I have url such as
/real_estates?cityId=100
. But from what I seeing in docs, I have to pass the id AND label. Problem is that I don't know the exact label by id at the moment of page loading. Is there a way to pass just an id?Beta Was this translation helpful? Give feedback.
All reactions