diff --git a/resources/lang/tr/filament-google-autocomplete-field.php b/resources/lang/tr/filament-google-autocomplete-field.php new file mode 100644 index 0000000..e35afea --- /dev/null +++ b/resources/lang/tr/filament-google-autocomplete-field.php @@ -0,0 +1,8 @@ + 'Aranıyor...', + 'autocomplete.search.prompt' => 'Arama yapmak için bir konum yaz', + +]; diff --git a/src/Concerns/HasGooglePlaceApi.php b/src/Concerns/HasGooglePlaceApi.php index 233429f..bd189d2 100644 --- a/src/Concerns/HasGooglePlaceApi.php +++ b/src/Concerns/HasGooglePlaceApi.php @@ -146,6 +146,9 @@ protected function getFormattedApiResults($data): array // array map with keys $addressFields = array_merge(...array_map(function ($key, $item) { + if (!isset($item['types']) || empty($item['types']) || !isset($item['types'][0])) { + return []; + } return [ $item['types'][0] => [ 'long_name' => $item[$this->currentApiNamingConventions['longText']], diff --git a/src/Forms/Components/GoogleAutocomplete.php b/src/Forms/Components/GoogleAutocomplete.php index ac22d92..052e7f5 100644 --- a/src/Forms/Components/GoogleAutocomplete.php +++ b/src/Forms/Components/GoogleAutocomplete.php @@ -72,6 +72,7 @@ public function getChildComponents(): array ->dehydrated(false) ->allowHtml() ->live() + ->required($this->getIsRequired()) ->placeholder($this->getAutocompletePlaceholder()) ->searchDebounce($this->getAutocompleteSearchDebounce()) // 2 seconds ->searchingMessage(__('filament-google-autocomplete-field::filament-google-autocomplete-field.autocomplete.searching.message')) @@ -288,4 +289,16 @@ protected function getAutocompletePlaceholder(): string { return $this->evaluate($this->autocompletePlaceholder) ?? __('Select an option'); } + + public function required(bool|Closure $condition = true): static + { + $this->isRequired = $condition; + + return $this; + } + + public function getIsRequired(): bool + { + return $this->evaluate($this->isRequired); + } }