diff --git a/CHANGELOG.md b/CHANGELOG.md index 47b8875..dc73c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.11.7] - 2020-04-16 +### Fixed +- combobox handling of existing selection. + +## [0.11.6] - 2020-03-22 +### Fixed +- asset injection to not break view, so that HTTP tests still work. + ## [0.11.5] - 2020-03-07 ### Added - searchField option to allow separation of database query search field and display field. diff --git a/composer.json b/composer.json index 902de1e..20b30e5 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ } ], "require": { + "fico7489/laravel-eloquent-join": "^4.1", "illuminate/config": "^7.0", "illuminate/support": "^7.0", "jenssegers/model": "^1.3", diff --git a/resources/views/components/tailwind/combobox.blade.php b/resources/views/components/tailwind/combobox.blade.php index 14a1e09..bb082c5 100644 --- a/resources/views/components/tailwind/combobox.blade.php +++ b/resources/views/components/tailwind/combobox.blade.php @@ -11,7 +11,8 @@ "valueField" => $options["valueField"] ?? "id", "placeholder" => $options["placeholder"] ?? "", "createFormView" => $options["createForm"] ?? "", - "query" => $options["query"] ?? "" + "query" => $options["query"] ?? "", + "value" => $value ?? null ]) @if (! $errors->isEmpty() && ! $errors->has($name)) diff --git a/src/Combobox.php b/src/Combobox.php index e253699..13feba6 100644 --- a/src/Combobox.php +++ b/src/Combobox.php @@ -1,5 +1,6 @@ createFormView = $createFormView ?: ""; $this->fieldName = $fieldName ?: ""; @@ -39,6 +41,12 @@ public function mount( $this->searchField = $searchField ?: ""; $this->valueField = $valueField ?: "id"; + if ($value) { + $value = json_decode($value, false); + $this->search = $value->{$this->labelField}; + $this->selectedValue = $value->{$this->valueField}; + } + if ($placeholder) { $this->placeholder = $placeholder; } @@ -60,9 +68,18 @@ public function render() } if ($query) { + if ($this->searchField) { + if (Str::contains($this->searchField, ".")) { + $query = $query->whereJoin($this->searchField, "ILIKE", "%{$this->search}%") + ->orderByJoin($this->searchField); + } else { + // TODO: refactor out from if-else. + $query = $query->where($this->searchField, "ILIKE", "%{$this->search}%") + ->orderBy($this->searchField); + } + } + $results = $query - ->where($this->searchField, "ILIKE", "%{$this->search}%") - ->orderBy($this->searchField) ->limit(100) ->get(); }