Checkbox how to handle in update form

how can i set the value of a checkbox to be checked if the value of the field in true when showing update form?

What I have done, and it seems to work, set the Static Value and the Checked value

Thanks @ben
I noticed the checked attribute but dont know what should i put ij the value

It depends. I want a value of 0 for No and a value of 1 for Yes. Therefore I have put 1 for the value.

So in the checked value
Are wappler expecting a boolean?
There is other places where its just not clear what the expected value is.
I wish the team put some information next to the values that explain this.

There is a checkbox group component in Wappler which is exactly for such cases.
Use it and put your checkbox inside it.

Add a value to the checkbox

and then assign the dynamic value from the database to the checkbox group component. It will auto-check the checkbox if value returned is equal to checkbox value


also setting the checked attribute to expression that will output true if its equal to the checkbox value will work as @ben said.

Yes, but it is easier with the checkbox component, especially with many checkboxes - as you don’t have to go through all of them and assigning conditions to them.

for future forms of course but since we didn’t know and don’t want to remove the checkbox we already have.

In my case I have in the database a table with numerous numeric fields (with value 0 or 1). I then have an update page, created by Wappler, where the numeric fields have been changed to checkboxes
How do I make sure that the checkbox fields are managed (checked / uncheked) and saved correctly?
Thank you

The value of a checkbox is submitted when it is checked. So set the value of the checkbox to 1. Then in your server action you use the default formatter to set the value to 0 when no value was submitted (when checkbox was not checked).

1 Like

But the chekbox is not checked

<div class="form-group">
         <div class="form-check">
            <input class="form-check-input" type="checkbox" value="1" id="1-dicembre-2018" name="1-dicembre-2018" dmx-bind:value="[0[1-dicembre-2018]]">
            <label class="form-check-label" for="1-dicembre-2018">1 dicembre 2 018</label>

When the checkbox is checked it will send β€œ1” as value to the server, when it is not checked it will not send a value to the server. On the server you use $_POST["1-dicembre-2018"] to read the value posted to the server, to set the value to β€œ0” in case of an unchecked checkbox you have to add a formatter on the expression like $_POST["1-dicembre-2018"].default(0).

Also I would recommend not to use - in the name/id of your form fields, they are not valid ids for App Connect and Server Connect.

Check my post above please. You need to add the checkbox group component in order to auto check it.

Ok Teodor
i select Checkbox App / Checkbox Group
but how do I insert all the checkboxes inside it?

Well, The same way you inserted them on your page :smiley:

I entered them with the generator

Marzio, Just move your checkbox inside the checbox group. Or create it manually … it does not matter.

Just add another input before your checkbox.
Name it the same as the checkbox.
Make it hidden field
Set the value to 0

Now if the checkbox is chekced the server will get 1 and if you leave it the server will get 0

@mrbdrm Patrick already explained how to use the default formatter in order to insert 0. No such "hacks" are needed or should be used.