Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Get value from fallback field #20

Open
meyer59 opened this issue Mar 22, 2021 · 5 comments
Open

Get value from fallback field #20

meyer59 opened this issue Mar 22, 2021 · 5 comments

Comments

@meyer59
Copy link

meyer59 commented Mar 22, 2021

Hello
Is it possible to get the value from a fallback field ?
For example: let's say you have a state field in your db, In the Google place response the state field is not always filled so you would rather fetch the value from the administrative_area_level_1.
This could also be the case for the city: for some city the locality is filled and for some others the vicinity is filled.
It could be great if we can specify fallback field for the same db value.
Cordially

@emilianotisato
Copy link
Owner

Sorry @meyer59 I did't test it with a fallback field. But I am guessing it should work ok

If you can make it work please let me know. Or feel free to send a PR with a possible solution, I will gladly take a look at your PR

@AndPicc
Copy link

AndPicc commented May 10, 2022

hello!
I have a similar problem and I think it would be enough if you could print out an empty string in case the value is not present when using the "combined" syntax for fromValue().

so like
->fromValue('{{locality}}{{postal_town}}')

at the moment the above will print either one of these cases:

undefinedCity Name
City Nameundefined

so if you add a check for "defined" before printing, this workaround would print out only the locality when it's present, OR the postal_town when there is that one instead.

p.s. thanks for this package! it really helped out a lot now that Nova Places is being deprecated.

@asad-mytake
Copy link

asad-mytake commented Nov 13, 2023

hello! I have a similar problem and I think it would be enough if you could print out an empty string in case the value is not present when using the "combined" syntax for fromValue().

so like ->fromValue('{{locality}}{{postal_town}}')

at the moment the above will print either one of these cases:

undefinedCity Name
City Nameundefined

so if you add a check for "defined" before printing, this workaround would print out only the locality when it's present, OR the postal_town when there is that one instead.

p.s. thanks for this package! it really helped out a lot now that Nova Places is being deprecated.

where exactly we have to put this defined check, will you please show me the code of that. i exactly want the same thing you mentioned above, if route is not defined then it shows undefined into concatination case (if i use {{parm1}} {{parm2}} it shows undefined if each of param is not defined)

@teamappelit
Copy link

teamappelit commented Nov 13, 2023

@asad-mytake facing the same issue when we add like {{route}} {{street_number}} in the AddressMetaField. So, if you resolved this issue or were able to find out any workaround then please share it here.

GoogleAutocomplete::make(__('Address'), 'address')
        ->nullable()
        ->rules('required', 'string', 'max:255')
        ->withValues([
            'route',
            'street_number',
            'postal_code',
            'locality',
            'administrative_area_level_1.long_name',
            'country.short_name',
            'latitude',
            'longitude',
        ])->placeType('address'),

  AddressMetadata::make(__('Address Line 1'), 'address_line_1')
      ->sortable()
      ->nullable()
      ->rules('nullable', 'required_with:address', 'string', 'max:255')
      ->fromValue('{{route}} {{street_number}}'),

when route and street_number do not exist then it become show in the AddressMetaField as undefined undefined.

@AndPicc
Copy link

AndPicc commented Nov 14, 2023

@asad-mytake I am sorry but mine was a suggestion to the package developer to introduce a conditional within its code, and skip the value when it's undefined rather than printing out "undefined".

Unfortunately we couldn't find a solution achievable with code from our side. In the end we just decided to pull from the fields that are more commonly used in UK.
Though the address is not a vital component on that website, and it's not tied with any functionality (i.e. we don't have to send parcels nor create official documents), hence it doesn't matter if it's not super precise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants