Recently I had been trying to implement laravel's livewire to submit form and refresh the page without actually using the contemporary ajax based flow. It works fine for everything except that I need to send some hidden input values also which I would be changing based on the user's action before submitting the form.
<input type="text" class="w-100 ratings-hidden" value="" wire:model="rating_val">
<input class="" value="" wire:model="reviewable_id" type="hidden">
<textarea class="form-control w-100 animated" cols="50" id="new-review" wire:model="comment" placeholder="Enter your review here..." rows="5"></textarea>
Here, the comment is fetched nicely after submission but I can not get the values of rating_val and reviewable_id
Remove the value="" from the input because livewire does it for you.
In your component set the properties, you need ($rating_val, $reviewable_id) and in your mount method, you initialise the value for those properties.
class ComponentName extends Component
{
public $rating_val;
public $reviewable_id;
public function mount()
{
$this->rating_val = "value_for_input";
$this->reviewable_id = "value_for_input";
}
}
In your blade file all you need is the following
<input type="hidden" wire:model="rating_val">
<input type="hidden" wire:model="reviewable_id">
you can't use hidden value or hidden input, but you can use this solution:
in your blade:
<form wire:submit.prevent="YourMethodName( {{ $param1 }} , {{ $param2 }})")>
<button type="submit" >Sned</button>
</form>
in your component:
public function YourMethodName($param1 , $param2)
{
dd([
'param1'=> $param1 ,
'param2' => $param2,
]);
}
It should be work, in the project I use this solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.