Skip Navigation

[Resolved] Several checkboxes are returning the checked value when unchecked

This support ticket is created 6 years, 4 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.

This topic contains 2 replies, has 2 voices.

Last updated by Beda 6 years, 4 months ago.

Author
Posts
#1126458

I am trying to:
We've used Types and Views to create a content template that displays a set of characteristics for the Unit Listing custom post type. We've defined several fields as checkboxes (Study, Media room, Rooftop terrace, Elevator, Gated community). When the box is checked, the content template should display "Study" (etc.), but when it's unchecked, it should display "no-study" wrapped in a span tag with the class "no-study," which renders it invisible. It has worked correctly in the past, but for some reason, all of unit listings are now displaying all of these characteristics, even when they're unchecked.

Link to a page where the issue can be seen:
hidden link

I expected to see:
On this particular unit listing, Study, Media room, Rooftop terrace, Elevator included, and Gated community are all unchecked, so none of those characteristics should be displayed.

Instead, I got:
All of the unchecked characteristics are displayed.

#1126491

At the client's request, I have temporarily hidden the problematic section of the unit listings by wrapping it in a span of the class "optional-details," but you can still view the problem area in the source code for purposes of troubleshooting.

#1126816

I think it is the same issue as reported to us here:
https://toolset.com/forums/topic/multiple-checkboxes-values-always-showed/

To confirm if this is the same BUG, I will below outline the symptoms and other details.

1. Create a Checkboxes field, several options, save 0 to the database if unchecked

2. Populate a post and check one of the options, save

3. Insert the ShortCode to display that field with Custom Values for checked and unchecked options like so:

[types field='checkboxes' state="checked" option="0"]s[/types]
[types field='checkboxes' state="unchecked" option="0"]n[/types]
[types field='checkboxes' state="checked" option="1"]s[/types]
[types field='checkboxes' state="unchecked" option="1"]n[/types]
[types field='checkboxes' state="checked" option="2"]s[/types]
[types field='checkboxes' state="unchecked" option="2"]n[/types]

etc

When you visit the post, you will see the Custom values for "checked" being output for all options, even if only one was checked

Expected is to see one Custom Value for checked and n for not checked.

This was broken with the 3.1 updates, before that, it works

Our developer has already proposed a fix, which is in code review.

A fast solution can be not to save 0 for those unchecked options.
To update existing fields, you might consider running a custom code:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/

I was not able to confirm this myself on your site as the Password provided was wrong, could you check and eventually add a new one, in case we need to take a look?