Support

Account

Home Forums Bug Reports Checkboxes no longer working

Solved

Checkboxes no longer working

  • Since the most recent update (4.1.8.1) some of my fields are no longer working.
    I have a bunch of different fields defined as for instance the following:

    label: Video
    name: video
    type: checkbox
    choices: 1:Yes
    not required, no default value, no conditional logic

    (i know btw this is a silly way of using checkboxes, but it’s a legacy thing from before acf…)

    since the update, new entries for this type of field no longer register, ie. checking the checkbox, will not create or update a custom field by the name of video although going back to the admin page the checkbox appears checked.

    i am stumped. i can provide a login url in a private message.

    HELP!!

  • I’m also having issues with checkboxes that default to checked. My fields are implemented via PHP, so if 'default_value' => 1 then the field always appears checked on edit screens, and if the associated post is saved, the field is cleared/removed from postmeta (though I should note that the hidden _name meta remains).

    Testing shows that defaulting the field to unchecked (i.e. 0) allows the field to display and store the data properly.

  • Hi guys.

    My bet is there is a bug when using the number 1 as the only choice.

    I’ll do some testing and get back to you.

    Cheers
    E

  • Hey guys.

    After a quick test, I can’t replicate the issue at all.

    The value ‘1’ is saving perfectly as a default value and as a normal selection.

    Is it possible that you have another field with the name field_name on the edit screen? This would cause the value to be overridden.

    Is it also possible that some sort of PHP error is occurring which is stopping ACF from saving completely?

  • i ran some tests and the problem is that the value is now saved as an array even if there is only one value. this causes issues for plugins doing things with custom fields and expecting strings. also support for arrays is limited in custom queries…

  • Hi @tpuell

    Yes, the checkbox field saves it’s data as an array. This is becuase they may be multipl values selected or 1.

    This way, the returned value is always an array which makes the front end code easier to use (don’t have to ask if it is or isnt an array – lots of noob devs had issues with this)

    Yes, the flip side to this is that the checkbox field is not good for creating a connection, but when you think about it, if you want to make a connection to another post, you only want 1 value, not multiple, so you should be using the select field instead.

    Are you able to use the select field?

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Checkboxes no longer working’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.