I'm having trouble passing the clicked on autocomplete element's value to my livewire search function when I click my search button. The search and autocomplete work, except that when I clicked on an element from the autocomplete dropdown that value is not what is passed to my live wire render function, only the manually typed-in characters are passed.
So for example, if I type in "Title of" and click "Title of Poster 1" from the autocomplete dropdown (putting "Title of Poster 1" text in the search input field). Then click search, only "Title of" is passed so the results include all posters with "Title of" in the title. I'm trying to acheive the result of only the poster with the title, "Title of Poster 1".
Seems like I have it setup so $search is only updated on the pressing of keys and doesn't update when a value is click from the auto complete dropdown.
Any help fixing this would be greatly appreciated.
my live wire component
class PosterData extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public $search;
public function render()
{
$posters = Poster::searchFilter([$this->search, '', ''])->with('author', 'category', 'country', 'profile')->paginate(10);
return view('livewire.poster-data', [
'posters' => $posters,
]);
}
}
the html
<div class="d-flex" id="searchBoxRow">
<input wire:model.defer="search" class="form-control mr-sm-2" id="inlineFormInput" val="" type="search" placeholder="Search Posters" aria-label="Search Posters" spellcheck="true">
<button wire:click="render" class="btn btn-primary" id="posterSearchButton" type="submit">
<i class="bi bi-search button-icon"></i>
<span class="button-text">Search</span>
</button>
</div>