How to use dynamic Switch instead of Checkbox in a form?

I have a checkbox, but would like to use Bootstrap Switch.
I can’t get it to work. Its dynamic, to pick up the value when = 1

<div class="form-check form-switch">
    <input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault">
    <label class="form-check-label" dmx-bind:for="insp_pck_status_{{$index}}">Default switch checkbox input</label>
</div>

I’m not 100% sure what you want to do.

But try add:

value="1"

To the <input>
This will send a value of 1 when you submit the form. Note:When the switch is unchecked it won’t send any value.

It’s not really clear what are you trying to do. Please explain a bit more detailed.
Also, when posting code make sure to format it as explained here:

1 Like

try:

<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault" dmx-on:changed="flexSwitchCheckDefault.setValue(checked?1:0)">

2 Likes

1.Just give the switch a static value of 1
2. Set checked in dynamic attributes to your switch value being equal to 1
3 In your server action add a default value of 0 to deal with when the switch is unchecked and hasn’t a value

2 Likes