cheesegrits / filament-google-maps

Google Maps package for Filament PHP
234 stars 65 forks source link

afterStateUpdated closure not firing #67

Open joseadrian opened 10 months ago

joseadrian commented 10 months ago

From the README, I copied this code and the map loads fine, however I was expecting the closure in afterStateUpdated to be fired since the readme says If you wish to update your lat and lng fields on the form when the map marker is moved:. Added a breakpoint, it looks like it doesn't fire, though it does when I click the lat or lng field and then click outside. Is it a bug?

    Map::make('location')
        ->reactive() // Changed this to ->live() because I am using filament v3
        ->afterStateUpdated(function ($state, callable $get, callable $set) {
            $set('latitude', $state['lat']);
            $set('longitude', $state['lng']);
        }),
widianapw commented 8 months ago

Hi, i face same issue here. does anyone know how to fix this?

cdelcastillomaussa commented 8 months ago

Si creo que es un error del mismo plugin

joseadrian commented 5 months ago

There is an ugly workaround. I don't know why for it to be triggered, you need a GeoJSON structure and an extra field. From one of the plugin's file, the markerMoved calls this.geoJsonContains method which needs those two things for the setStateUsing function to be fired. There must be a reason but I don't know what that is.

Create a simple field, call it however you want.

Forms\Components\TextInput::make('any_name'),

Then to the Map field, add this piece of code:

Map::make('your_field')
   ->geoJson(function() { return '{}'; })  
   ->geoJsonContainsField('any_name')

Then somehow, hide the field using css. It won't work if you use the method visible or hidden on the field. Demo? Also, you need to add work with the model with that new field.

holmesadam commented 3 months ago

Any idea on a fix for this rather than the "ugly workaround" @cheesegrits? Thanks