I am using Laravel with alpinejs version 3.2.4. I would like to show/hide some input elements and show them based on what the user selects. This is my code:
<form x-data="{payFor: ''}">
<select x-model="payFor" name="payFor">
<option value="service">Service</option>
<option value="product">Product</option>
</select>
<div x-show="payFor == 'service'">
<select name="serviceId">
@foreach($services as $service)
<option value="{{ $service->id }}">{{ $service->service_name }}</option>
@endforeach
</select>
</div>
<div x-show="payFor == 'product'">
<select name="productId">
@foreach($products as $product)
<option value="{{ $product->id }}">{{ $product->product_name }}</option>
@endforeach
</select>
</div>
</form>
This doesn't seem to be working on my forms and I cannot figure out why. When the form loads, all the controls are shown and on selection, none hides. Even when I try to set default x-data="{payFor: 'service'}"
it still doesn't work either. Any solution to this?