Home Forums Add-ons Repeater Field Add Class to Repeater Field w/ Checkbox


Add Class to Repeater Field w/ Checkbox

  • Hi All!

    I have an ACF Options page setup with a repeater. It is used to manage a careers page. One repeater group creates a job listing with job title, job description and then a nested repeater for creating a list of job requirements.

    I want to be able to add a checkbox that is used to ‘Unpublish’ a particular job listing so a user does not have to delete the listing. They will simply check the ‘Unpublish’ checkbox and that job listing will be removed from the website.

    My thinking is having the checkbox add a class to the div containing the field and setting that class to display:none.

    I’m struggling to find any information about how to accomplish this. I’m not sure how ACF can be used to add classes. Thoughts?

    Thanks in advance!

  • Hi @robertrhu

    Thanks for reaching out to us.

    As opposed to using a checkbox, I would recommend using a true/false field. This will return true if selected and thus you can display the selected sub_field.

    If you would like to make use of the display none, you may do it as follows

    $selected = get_sub_field('field_name','option');
    $html =  "<div "
    $html.='style = "display:none;"';
    $html.=">My FAQ content here </div>"; 

    Hope this helps.

  • Thanks for the response James!

    So if I use true/false field how does that get implemented in the PHP code to display/not display the sub field?

  • Hi @robertrhu

    Thanks for the follow up.

    Not certain I understand your question. However, the sample code shared illustrates how the field can be used on the template file (frontend).

    If the value is not selected, then you append the hide option.

    Let me know more on where you are stuck.

  • Thanks for the quick response James.

    I thought the code snippet you provided was to append display: none using a checkbox? I’m asking how to implement the true/false field to display/not display a sub field as you describe.

  • Hi @robertrhu

    I believe you we may not be on the same page on this issue.

    The true/false field is represented as a checkbox, the only difference is that instead of selected options, it returns true or false.

    One you load the value of the field, ( true/false ) you can then use the value to dertermine the layout structure.

    If this is not what you are looking at, kindly explain to me more step by step on what you are working on so that I may be able to assist further.

    Hope to hear from you soon.

  • Thanks James! I think we’re on the same page now.

    I’m going work on implementing this tonight or tomorrow. I’ll circle back with progress soon.

    Thanks again, as always! 🙂

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

The topic ‘Add Class to Repeater Field w/ Checkbox’ is closed to new replies.