fix: fill location from autocomplete (#71)
This commit is contained in:
parent
1471bf94dd
commit
4c26928d23
@ -42,21 +42,29 @@ export const LocationInput = memo(
|
|||||||
|
|
||||||
const onInputChange: InputProps['onChange'] = async (e) => {
|
const onInputChange: InputProps['onChange'] = async (e) => {
|
||||||
const newInputValue = e.target.value;
|
const newInputValue = e.target.value;
|
||||||
setInputValue(newInputValue);
|
|
||||||
|
|
||||||
if (newInputValue.trim().length > 3) {
|
if (
|
||||||
try {
|
isValidLocation(newInputValue) &&
|
||||||
const address = extractAddress(newInputValue);
|
(await isRealLocation(ymaps, newInputValue))
|
||||||
const results = await ymaps.suggest(address);
|
) {
|
||||||
setSuggestions(results);
|
onChange(newInputValue);
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setSuggestions([]);
|
setInputValue(newInputValue);
|
||||||
}
|
|
||||||
|
|
||||||
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
if (newInputValue.trim().length > 3) {
|
||||||
|
try {
|
||||||
|
const address = extractAddress(newInputValue);
|
||||||
|
const results = await ymaps.suggest(address);
|
||||||
|
setSuggestions(results);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setSuggestions([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFocus: InputProps['onFocus'] = () => {
|
const onFocus: InputProps['onFocus'] = () => {
|
||||||
@ -103,7 +111,7 @@ export const LocationInput = memo(
|
|||||||
{...props}
|
{...props}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
value={inputValue}
|
value={inputValue ?? value}
|
||||||
onChange={onInputChange}
|
onChange={onInputChange}
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
placeholder={t('placeholder')}
|
placeholder={t('placeholder')}
|
||||||
|
Loading…
Reference in New Issue
Block a user