laravel-splade icon indicating copy to clipboard operation
laravel-splade copied to clipboard

Fill checkboxes from default-values

Open JapSeyz opened this issue 2 years ago • 1 comments

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.

JapSeyz avatar Oct 09 '22 01:10 JapSeyz

Thanks for reporting. I'll take a look at it!

pascalbaljet avatar Oct 11 '22 10:10 pascalbaljet

Can confirm, working on a fix!

pascalbaljet avatar Oct 20 '22 15:10 pascalbaljet

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 a boolean type for the attributes.
  • Add value="1" to the checkbox elements. I thought the default value was 1, but it turns out Vue has a default value of true. I've updated the docs accordingly.

pascalbaljet avatar Oct 20 '22 17:10 pascalbaljet

Sweet, it works!

JapSeyz avatar Oct 21 '22 22:10 JapSeyz