diff --git a/src/components/order-form/form/location/location-input/location-input.tsx b/src/components/order-form/form/location/location-input/location-input.tsx index dac3d86..e28f18c 100644 --- a/src/components/order-form/form/location/location-input/location-input.tsx +++ b/src/components/order-form/form/location/location-input/location-input.tsx @@ -42,21 +42,29 @@ export const LocationInput = memo( const onInputChange: InputProps['onChange'] = async (e) => { const newInputValue = e.target.value; - setInputValue(newInputValue); - if (newInputValue.trim().length > 3) { - try { - const address = extractAddress(newInputValue); - const results = await ymaps.suggest(address); - setSuggestions(results); - } catch (error) { - console.error(error); - } + if ( + isValidLocation(newInputValue) && + (await isRealLocation(ymaps, newInputValue)) + ) { + onChange(newInputValue); } else { - setSuggestions([]); + setInputValue(newInputValue); + + 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); } - - setIsSuggestionsPanelOpen(suggestions.length > 1); }; const onFocus: InputProps['onFocus'] = () => { @@ -103,7 +111,7 @@ export const LocationInput = memo( {...props} ref={ref} onBlur={onBlur} - value={inputValue} + value={inputValue ?? value} onChange={onInputChange} onFocus={onFocus} placeholder={t('placeholder')}