Support

Account

Home Forums Add-ons Repeater Field Pass a repeater field value on click?

Solving

Pass a repeater field value on click?

  • I have a website where I use ACF with repeater fields (courses : different groups and dates). One of these field is an url to an external site (for registration). I’m able to output it directly throught the loop, but that’s not what I want 🙂

    I want the person to first click on a button (which is shown if the field in question is not empty), which shows a warning pop-up and then, in that pop-up, I want to put the link (field value.

    How can I manage to “pass” the value into that pop-up? Note that the pop-up is used for one or more courses on the same page.

    I tried to use “the_sub_field” in a href, but it doesn’t work. Ex . : ” class=”et_pb_button_mia” target=”_blank” id=”miaLink”>

    I tried to “store” the value in a variable, but it doesn’t work…

    If I make a loop into the popup, it will shows all the values of the sub field… I only want to show the value of the sub field of the cours the clicked on…

    Thanks

  • There isn’t enough information to clearly understand what you’re trying to do. This could be partially do to the forum eating half of your code because you did not use code tags.

    Exactly how are you creating the “pop up”?

  • Hi,

    sorry it’s my first topic 🙂

    Maybe it will be clearer with proper code.
    So, first, I have a CPT for courses.
    In that CPT, I use ACF for the details of the courses.
    One of the field is a repeater field : each course cans have multiple group (each group have a different start time and an URL to register).
    On the courses page, I display the groups using the following code:

    <?php if(have_rows('gestion_groupe')){ ?>
        <div id="accordion">
            <?php  while (have_rows('gestion_groupe')): the_row(); ?>
                   <div>
    <?php if (get_sub_field('fraisEQ') != NULL) { ?>
     <div class="ligne"><span style="font-size:13px;"><strong>Groupe Emploi-Québec</strong> : 
       <?php echo get_sub_field('fraisEQ'); ?> $</span>
         <button onclick="hiddenLinks('<?php the_sub_field('ns_lienMiaEQ'); ?>','<?php the_title(); ?>','<?php the_title(); ?>')" class="et_pb_button_mia">S'inscrire</button>
              </div>
    <?php
     }
      ?>
    </div>
    <?php
         endwhile;
            ?>

    What I want here, is to display a button if there’s a group (get_sub_field…).
    If the person click on the button, the popup will appears. I want to have the link in that pop-up. Each group have a different link…

    My popup is an hidden div on the page :

    <div id="overlay" onclick="off()">
    <div id="overlayText">
    [I have text...]		
    <a href="<?php echo the_sub_field('ns_lienMiaEQ'); ?>" class="et_pb_button_mia" target="_blank" id="miaLink">Button text</a>
    

    And I’ve got a js function :

    function hiddenLinks() {
        document.getElementById("overlay").style.display = "block";
    }
    
    function off() {
        document.getElementById("overlay").style.display = "none";
    }

    If it’s still unclear, let me know and thanks for the help.

  • I would probably use a different modal for each group with the information pre-populated. Each button would open a different modal.

    To do it with a single modal and JS you still need to output what you want hidden in the section somehow and then the script for the modal would need to get that information and insert it into your modal. How exactly you would do that I’m not sure.

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

The topic ‘Pass a repeater field value on click?’ is closed to new replies.