I have a button that I want to toggle the value on a html input element from 0 to 1 and vice versa but I can't figure out how to do it with Alpine JS.
// input will be 0 or 1
<input type="hidden" value="0" name="status" x-ref="status">
// Toggles the status between 1 and 0
<button type="button"
x-data="{ on: false }" :class="{ 'bg-gray-200': !on, 'bg-primary-600': on }"
@click="$refs.status.value = 1"
>Toggle Status</button>
I was able to get the code above to change the input value to 1 but can't figure out how to get it to toggle it back and forth. Any ideas would mean a lot.