Skip Navigation

[Resolved] Custom fields Checkbox and Required option

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.10 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1555431

Tell us what you are trying to do?

In the list of my custom fields, I have set some of them to "Checkbox" type, and I have set the value to 1 when checked, and I have also set the option to set it to the value 0 when it is not checked. Then I have set the field to be "required".
In the backend, when I do insert a new custom post, the problem is that if I do not check it, I got the error message because the item is empty. So the 0 value is not set automatically.
Should I do not use required field option when using checkboxes in this way?
Or how can I have it set to 0 by default?

#1555765
checkbox.JPG

Hello,

In your case, you do not need to enable the option "required", since if enable option "required", you will need to check the checkbox field when you save the post, soit won't save 0 value into database.

And according to our errtum, there is a known issue with the checkbox field using 0 value:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/

So if you want to use this custom checkbox to filter the view's result, it is recommended to use option:
"When unchecked, don't save anything to the database".

See screenshot: checkbox.JPG