Code Monkey home page Code Monkey logo

nova-google-autocomplete-field's People

Contributors

anotherfrontendguy avatar bernhardh avatar chrisbjr avatar dniccum avatar emilianotisato avatar ibrahim-mubarak avatar nickpoulos avatar skullbock avatar swilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nova-google-autocomplete-field's Issues

Get value from fallback field

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

save the entire place data as json ?

This is what I wanted to do from the beginning.. I don't want to cherry pick fields at the time of saving, I want to save the entire dataset returned by google as json and deal with it later.

Is there no simple way of doing this? I would have thought this would be the first thing such a package would offer...

Debounce after 5 seconds

Hi,

Thanks for building this field, it have a lot of potential to be used widely!

Still, I think there is an enhancement that will allow the google places api quota (for free usage) not to be exceeded so fast, in case you can use a debounce option.

Meaning, you should only send the request when the user "stops writing in the field after X seconds".

User starts writing the address.
Then he stops writing.
Field waits 5 seconds.
Then makes the HTTP call.

This would reduce drastically the usage of the HTTP requests to the Google places API.

Thanks,
Bruno

Manage additional values when there are more than one field

In order to use fromValue, optional value names (e.g. latitude, longitude) are required.
But when there are more instances, names are not unique and there are no way to distinguish above them.
Is there a way to overcome this problem?

TypeError

Hello,

I am getting this error. Autocomplete is working, but metadata are not updated:

TypeError: null is not an object (evaluating 'attribute.match(/[^\[\]]+\[([^\[\]]+)\]/)[1]')

Any ideas?

Choose field value dynamically on the fly based on places result

For now we can bind field one to one using fromValue() but is there any way to tell that if street_address is not empty use that value otherwise use route field from withValues array?

I have below implementation:

     * Get the address fields for the resource.
     *
     * @return \Illuminate\Http\Resources\MergeValue
     */
    protected function addressFields()
    {
        return $this->merge([
            GoogleAutocomplete::make('Search Address To Auto-Fill Data Below', 'address')->withValues([
                'street_number',
                'route',
                'locality',
                'administrative_area_level_1',
                'postal_code',
                'country',
                'latitude',
                'longitude'
            ])->hideFromIndex()->hideFromDetail(),
            AddressMetadata::make(__('Building Number'), 'building_number')->fromValue('street_number')->hideFromIndex(),
            AddressMetadata::make(__('Street'), 'street')->fromValue('route')->hideFromIndex(),
            AddressMetadata::make(__('City'), 'city')->fromValue('locality')->hideFromIndex()->rules('required'),
            AddressMetadata::make(__('State'), 'state')->fromValue('administrative_area_level_1')->hideFromIndex(),
            AddressMetadata::make(__('Zip Code'), 'zip_code')->fromValue('postal_code')->hideFromIndex(),
            AddressMetadata::make('hidden_country', 'hidden_country')->fromValue('country')->invisible()->hideFromIndex()->hideFromDetail(),
            BelongsTo::make('Country', 'country', 'App\Nova\Country')->display(function($m) {
                return $m->name;
            })->hideFromIndex()->rules('required'),
            AddressMetadata::make('Latitude', 'latitude')->fromValue('latitude')->hideFromIndex(),
            AddressMetadata::make('Longitude', 'longitude')->fromValue('longitude')->hideFromIndex(),
        ]);
    }

Why are you dont use remoteScript?

class FieldServiceProvider extends ServiceProvider
{
   /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
       ...
       Nova::serving(function (ServingNova $event) {
            Nova::script('google-autocomplete', __DIR__.'/../dist/js/field.js');
            Nova::style('google-autocomplete', __DIR__.'/../dist/css/field.css');
            Nova::remoteScript('https://maps.googleapis.com/maps/api/js?key='.config('google-autocomplete.api_key').'&libraries=places');
            Nova::provideToScript([
                'google_autocomplete_translations' => $this->getTranslations(),
            ]);
        });
    }
   .....
}

How to choose long_name over short_name from auto-complete address metadata fields?

I have used address metadata fields to append values as mentioned in #13 (comment).
The problem is administrative_area_level_1 fills short_name instead of long_name in input field.

For example, in below google places response:

"address_components" : [
         {
            "long_name" : "Gulbarga",
            "short_name" : "Gulbarga",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Revana Siddeshwara Colony",
            "short_name" : "Revana Siddeshwara Colony",
            "types" : [ "sublocality_level_1", "sublocality", "political" ]
         },
         {
            "long_name" : "Gulbarga",
            "short_name" : "Gulbarga",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "Karnataka",
            "short_name" : "KA",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "India",
            "short_name" : "IN",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "585104",
            "short_name" : "585104",
            "types" : [ "postal_code" ]
         }
      ],

it fills out KA in forValue('administrative_area_level_1') field.

Strange Error On Production - EmilianoTisato\GoogleAutocomplete\GoogleAutocomplete::placeType does not exist.

I have been using this package in local Homestead without any issues. However, after pushing to a DigitalOcean ubuntu box via Forge I am now getting an odd error on both create/index views.

The actual errors are occurring when the Nova API tries to get the field list via:

/nova-api/businesses/creation-fields?editing=true&editMode=create&viaResource=&viaResourceId=&viaRelationship=

This dies with a:

BadMethodCallException
Method EmilianoTisato\GoogleAutocomplete\GoogleAutocomplete::placeType does not exist.

My .env is setup correctly, all the calls appear to be the same, not quite sure what is happening.

Anybody else see this behavior at all?

Match Nova CSS error classes

Thank you for this amazing package ๐Ÿ‘

One thing I noticed is that Nova uses different (CSS) classes when displaying errors, which results in two different font-sizes and font-styles being shown (if you combine this package with other Nova validations).

demo

Could you please consider matching the class names in order to avoid this "mismatch"?

Nova (I currently use v2.12.0) uses these classes for error messages:

.help-text.error-text.mt-2.text-danger

If you want, I can even create a PR for it.

Cheers and thank you

Cannot search by establishment

I am trying to search by business name and I cannot get this to pull results. Typing out business names return no addresses (blank).
Any idea what I need to do?
I have tried the following:
GoogleAutocomplete::make('Address') ->placeType('establishment') ->withValues(['latitude', 'longitude','formatted_address','name']) ->hideFromIndex() ->nullable(),

Extracting address_line_1 from GoogleAutocomplete

Right now I have a full address form in Nova and I'm using this package to autocomplete the address. I'd like to extract address_line_1 into it's own field. I have GoogleAutocomplete::make('Address Line 1')->withValues([...]) but it's setting 'Address Line 1' to be the full address (123 Main Street, City, State Zip, Country).

Whats the best way to go about having the auto-complete field only populate with the address_line_1 and not the full postal address?

Currently:

    protected function addressFields()
    {
        return [
            GoogleAutocomplete::make('Address Line 1')->withValues([
                'locality',
                'administrative_area_level_1',
                'postal_code',
                'country',
                'latitude',
                'longitude'
            ])->countries(['CA']),
            
            Text::make('Address Line 2')->hideFromIndex(),
            AddressMetadata::make('City')->fromValue('locality')->hideFromIndex(),
            AddressMetadata::make('Province')->fromValue('administrative_area_level_1')->hideFromIndex(),
            AddressMetadata::make('Postal Code')->fromValue('postal_code')->hideFromIndex(),
            AddressMetadata::make('Country')->fromValue('country')->hideFromIndex(),
            AddressMetadata::make('Latitude')->fromValue('latitude')->disabled()->hideFromIndex(),
            AddressMetadata::make('Longitude')->fromValue('longitude')->disabled()->hideFromIndex(),
        ];
    }

All fields populate properly except Address Line 1 which is the full postal address, not just the street address as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.