Open brain82 opened 10 months ago
I have the same issue also @brain82 have you found a solution for it?
@khairy-pelcro After quite a bit of messing about to identify the cause, I found that it was an issue with Livewire and not the component (see the comment in code block below).
I ended up extending the Geocomplete field and changing the way the state
and getFormattedState
functions work.
namespace App\Forms\Components;
use Cheesegrits\FilamentGoogleMaps\Fields\Geocomplete;
class CustomGeocomplete extends Geocomplete
{
public function state(mixed $state): static
{
if ($this->getIsLocation() && is_array($state)) {
// IMPORTANT
// If all keys in the array are not set, it is important to set the state to null
// Otherwise, a livewire bug will occur where only the first key in the array will be set
// when the state is referenced in the afterStateUpdated callback
$lat = $state['lat'] ?? null;
$lng = $state['lng'] ?? null;
if (empty($lat) || empty($lng)) {
$state = null;
}
}
return parent::state($state);
}
public function getFormattedState(): string
{
$state = $this->getState();
if ($this->getIsLocation()) {
return $state ? $state['formatted_address'] ?? '' : '';
}
return $state;
}
}
Thanks really appracited
See screenshots below.