feat: Display existing address value in edit mode#67
Open
csh-tech wants to merge 1 commit intoTappNetwork:4.xfrom
Open
feat: Display existing address value in edit mode#67csh-tech wants to merge 1 commit intoTappNetwork:4.xfrom
csh-tech wants to merge 1 commit intoTappNetwork:4.xfrom
Conversation
feat: Show existing field value when editing a record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
afterStateHydrated()callback that checks if the first field has an existing value, and if so, sets the select state to 'existing'getOptionLabelUsing()logic to return the actual field value when the state is 'existing'afterStateUpdated()to ignore the 'existing' state (prevents clearing fields when the existing value is displayed)How it works
afterStateHydratedchecks if the firstwithFieldsfield has a valuegetOptionLabelUsingthen displays that value in the select fieldUsage
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
after
