-
Is there a way to preselect value based on id ?. e.g : when i use it on edit form, so the data already prefilled. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You sure can! Say you were working with client models. To use the autocomplete component, you need to provide the text, ID and results as separate public properties in your parent livewire component. So for example, prior to rendering, you would set <x-lwa::autocomplete
name="my-autocomplete"
wire:model-id="clientId"
wire:model-text="clientName"
wire:model-results="clients"
wire:focus="getClients" |
Beta Was this translation helpful? Give feedback.
-
@bumpyy yeah @dircm is correct, you can preselect a value by loading the value from your selected model into whatever property you have bound to |
Beta Was this translation helpful? Give feedback.
-
Thank's, that make sense, so i just have to query the user by id in the mount lifecycle hook right ? |
Beta Was this translation helpful? Give feedback.
You sure can! Say you were working with client models. To use the autocomplete component, you need to provide the text, ID and results as separate public properties in your parent livewire component. So for example, prior to rendering, you would set
$this->clientID = clientModel->id
and$this->clientName = clientModel->title
. You just need to configure the component with the pre-loaded properties like below.