Skip to content

Comments

feat: Display existing address value in edit mode#67

Open
csh-tech wants to merge 1 commit intoTappNetwork:4.xfrom
csh-tech:4.x
Open

feat: Display existing address value in edit mode#67
csh-tech wants to merge 1 commit intoTappNetwork:4.xfrom
csh-tech:4.x

Conversation

@csh-tech
Copy link

@csh-tech csh-tech commented Dec 2, 2025

Problem

When editing an existing record, the Google Autocomplete select field shows an empty placeholder ("Type an address to search...") instead of displaying the currently saved address value. This creates a poor user experience as users cannot see what address is already stored.

Solution

This PR adds support for displaying the existing value from the first field in withFields() when editing a record.

Changes

  1. Added afterStateHydrated() callback that checks if the first field has an existing value, and if so, sets the select state to 'existing'
  2. Added getOptionLabelUsing() logic to return the actual field value when the state is 'existing'
  3. Modified afterStateUpdated() to ignore the 'existing' state (prevents clearing fields when the existing value is displayed)

How it works

  • On form load (edit mode), afterStateHydrated checks if the first withFields field has a value
  • If a value exists, the select state is set to 'existing'
  • getOptionLabelUsing then displays that value in the select field
  • When the user searches for a new address, normal behavior continues
  • No breaking changes - works automatically with existing implementations

Usage

No changes required. Existing implementations will automatically show the saved address when editing:

My code was

Group::make([
                                        GoogleAutocomplete::make('full_address')
                                            ->autocompleteSearchDebounce(400)
                                            ->autocompleteFieldColumnSpan(1)
                                            ->countries([
                                                'IL',
                                            ])
                                            ->language(app()->getLocale())
                                            ->withFields([
                                                Hidden::make('full_address')
                                                    ->extraAttributes([
                                                        'data-google-field' => '{country}, {locality}, {route} {street_number}',
                                                    ]),
                                            
                                                Hidden::make('city')
                                                    ->extraAttributes([
                                                        'data-google-field' => '{locality}',
                                                    ]),

                                                Hidden::make('street')
                                                    ->extraAttributes([
                                                        'data-google-field' => '{route}',
                                                    ]),
                                            .....................
                                                    ]),
                                            ]),

Nothing showed up when I edited.
While there was data
before
image

after
image

feat: Show existing field value when editing a record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant