Support

Account

Home Forums Front-end Issues Link checkboxes / trigger checkbox item

Helping

Link checkboxes / trigger checkbox item

  • The first issue I had was how to link checkboxes. When selecting one checkbox another one from another field should be selected as well.

    Like this:

    What should be smart?
    • Windows
    • Doors
    x Lights
    • nothing

    What do you need?
    x Smart home Station
    x Lights with WLAN
    • electric doors
    • electric windows

    When the user is selecting “lights”, the first and second checkbox should be checked. I have achieved this with jQuery and Click Trigger but it has its problems and is not reliable.

    Try 1: trigger click on input.
    Fail: does not trigger the “selected” class event and connected conditions of the field group of acf.

    Try 2: trigger click on label.
    Fail: does trigger acf events but does not work properly in Safari / on iPad and not on hidden field.

    So I can rebuild the functions and combine clicking and adding classes but I wanted to do this with acf features like

    acf.getField('field_62d4abc0fbfd4').set('value', array(1, 3)) or
    acf.set('field_62d4abc0fbfd4', array(1, 3))

    So I’d like to link checkboxes but the feature I’m looking for is the properly and reliably trigger a checkbox item while clicking on a different element/button/item.

  • https://www.advancedcustomfields.com/resources/javascript-api/#acf.field

    try this, but I don’t know if it will work. I have not tried it when setting a checkbox field.

    
    var field = acf.getField('field_62d4abc0fbfd4');
    field.val([1,3]);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.