react-google-maps-api
react-google-maps-api copied to clipboard
Autocomplete initial value
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
I found out how. Thank you.
@mp3por How did you do it? I'm trying but can't figure it out
@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.