laravel-splade
laravel-splade copied to clipboard
Fill checkboxes from default-values
Hi,
I'm testing out Splade, and it seems the checkboxes doesn't auto-check based on the :default
provided to the form.
Nor can I programatically select it with a checked
prop.
What am I doing wrong?
<x-splade-form :action="route('house.update', $house)" :default="$house" class="space-y-4">
<x-splade-group>
<x-splade-checkbox name="pool" label="Pool" />
<x-splade-checkbox name="fenced_in" label="Fenced in" />
<x-splade-checkbox name="pets_allowed" label="Pets allowed" />
</x-splade-group>
</x-splade-form>
I've dd'ed
out $house
to ensure that pool
, fenced_in
and pets_allowed
are in the model, and equal to 1
, however the checkboxes still seem to be unchecked.
Thanks for reporting. I'll take a look at it!
Can confirm, working on a fix!
This has been fixed in v0.6.5. There are two ways of solving the issue:
- You may use Attribute Casting on your
House
Eloquent Model and add aboolean
type for the attributes. - Add
value="1"
to the checkbox elements. I thought the default value was1
, but it turns out Vue has a default value oftrue
. I've updated the docs accordingly.
Sweet, it works!