react-google-maps-api icon indicating copy to clipboard operation
react-google-maps-api copied to clipboard

Autocomplete initial value

Open mp3por opened this issue 2 years ago • 3 comments

How to set the autocomplete initial value.

UseCase - I use the autocomplete component when a user wants to select his address. Once I know his address he can always go back and change it. When he enters the "select user address" page I want to prepopulate the search with the users previous selection, however I can not do it.

Please help

mp3por avatar Oct 09 '23 14:10 mp3por

I found out how. Thank you.

mp3por avatar Oct 09 '23 14:10 mp3por

@mp3por How did you do it? I'm trying but can't figure it out

nalnir avatar Nov 29 '23 11:11 nalnir

@mp3por How did you do it? I'm trying but can't figure it out

<FormField control={form.control} name='address' render={({ field }) => ( <FormItem> <FormLabel variant={'text'} className={cn('font-bold')}> <TranslatedMessage stringKey={'centerLabel'} namespace={'AoiSettings'} /> </FormLabel> <FormControl> <Autocomplete onLoad={(autocomplete) => setAutocomplete(autocomplete)} options={{ componentRestrictions: { country: ['bg', 'ro'] }, fields: ['address_components', 'formatted_address', 'geometry', 'name', 'place_id'], }} onPlaceChanged={handleAutocompleteSelect} > <Input placeholder={t('address')} {...field} value={field.value} /> </Autocomplete> </FormControl> <FormFieldErrorMessage /> </FormItem> )} />

I use the placeholder attribute of the Input element.

mp3por avatar Dec 09 '23 13:12 mp3por