You can have the button trigger a function then have the function emit an event that will get picked up by livewire if you really need to run the javascript before the wire:click
action. But I’d have to wonder what you’d need a read-only field for and if there’s a better way to accomplish this. Maybe a hidden input? This doesn’t really feel livewire-y to me. It seems like you’re submitting a form and that’s it.
If you’re intent on going down this path, this might work for you:
<button type="button" onclick="javascript:$('#testfield').attr('readonly', false); Livewire.emit('storeFields')" class="btn btn-primary">Save</button>
Component.php
protected $listeners = ['storeFields'];
public function storeFields() // must be the same as the listener, or you need to define the function in the listener array
{
// whatever you're trying to do.
}
Again, I’m unsure why you need the field read-only and if you’re wire:model
-ing that field, livewire should send that field through regardless if it’s read-only or not.