Unchecked box input value of zero


I need this checked box to input a value of 0 if not checked and a value of 1 if checked. I have it right now so if checked it inputs but can’t figure out the opposite. Any help would be appreciated.

You should be ok with $_POST.Is_Rule.default(0)…

I don’t understand why not

Can you add a setValue step in your serveraction, assign the $_POST.Is_Rule to it and eneable the output?
eg: set Value isRule = $_POST.Is_Rule and enable output
Then check your dev network for isRule’s value in both cases (when checkbox is checked and unchecked).

*another thing you could try is to add a set Value step like that:
setValue isRule = $_POST.Is_Rule==1?1:0
and assign this isRule value to your database updater instead of $_POST.Is_Rule.default(0)

I’ll give it a try, thank you

1 Like

could you show me what you mean by this? Having trouble replicating this

is this what you mean

1 Like

It doesn’t work for when the box is checked, and when the box isn’t checked

It works for me…

1 Like


still is returning an error

When a checkbox is submitted, if unchecked, then no value is sent at all.
Personalty, assuming you are doing a database action,I set the update/inset to $_POST.mycheckbox.default(0)
So if a value is sent I.e. 1 is is used for update otherwise the field is set to the default of 0

Hi Hyperbytes, I followed your YouTube tutorial where you did this. Is the screenshot above not doing the post default(0) properly?

Well remove the validation from this POST var. It’s currently stopping your server action from submitting!

2 Likes

That works to submit, and when submitted it is a value of 0 now. But it’s zero even when the box is checked as well, plus I do need this checked box to filled out so how do I require this field without it reporting an error

setValue before the database insert…

Well have you added a value of 1 to it in App Connect / properties panel?

Well this makes no sense to me. You want to be able to submit it unchecked and submit 0, but then you require it, so it can’t be unchecked … can you please clear the things here?

Well, if you need it checked, why do you need an unchecked value?

Sorry, you’re totally right. In my database I have it as not null which is different than the validate step. My mistake.

<input class="form-check-input" type="checkbox" value="1" id="is_Rule" name="is_Rule" dmx-bind:checked="1">

dmx-bind:checked="1"

I’m sorry… you don’t mean in here do you. I hope I’m close to the right place

It worked, thanks to everyone who helped me! I appreciate all the feedback thus far.

1 Like