I am working on a laravel 8 and livewire project where I need to insert a dynamic value to an input according to the value that I select in the select, I was trying with the updatedFoo example method of livewire but I couldn't get it to work.
this is my select
<label class="form-label required" for="id_deliveryway">{{ trans('cruds.order.fields.id_deliveryway') }}</label>
<x-select-list class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required id="id_deliveryway" name="id_deliveryway" :options="$this->listsForFields['id_deliveryway']" wire:model="order.id_deliveryway_id" wire:change="change"/>
<div class="validation-message">
{{ $errors->first('order.id_deliveryway_id') }}
</div>
<div class="help-block">
{{ trans('cruds.order.fields.id_deliveryway_helper') }}
</div>
and this is where I look to insert a dynamic text
<div class="col-span-3 sm:col-span-3">
<label class="form-label required" for="address">Forma de envio</label>
<input class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" type="text" name="pickupdelivery" id="pickupdelivery" required wire:model="pickupdelivery">
<div class="validation-message">
{{ $errors->first('order.address') }}
</div>
<div class="help-block">
{{ trans('cruds.order.fields.address_helper') }}
</div>
</div>
I have tried with a function like this but nothing
public function change()
{
dd("Here");
}
try with updatedFoo, ie
public function updatedId_deliveryway_id()
{
$this->pickupdelivery = "Cualquier texto a insertar";
}
But it didn't work either, I ask you for a little help with my code to solve my problem please. Thanks.
I think you could work better with JavaScript, I'm attaching an example I hope it can help you.
Well I have solved it using the updatedFoo method (example of livewire) that is to say a lifecycle hooks, what I did was change the value of my view
wire:model="order.id_deliveryway_id"
to justwire:model="id_deliveryway"
declare it as a public propertypublic $id_deliveryway;
and then perform this functionThat is, it receives the id_deliveryway from the select and when it is updated, that is, it changes from one value to another, then it executes the query to the DeliveryMethod model to fetch the address that is inserted in the input text.
I leave you the solution in case someone has the same need or problem in the future...