Support

Account

Home Forums General Issues Problem with a repeater field (select + number field)

Solving

Problem with a repeater field (select + number field)

  • Hi, i’m having some issue with loading dynamically i have been trying things around without success :/

    I have the field “representation” (Repeater)

    Inside i have:

    date_where” (text)
    categorie_price” (Repeater)

    Inside of this repeater i have :

    categorie_age” (list)
    place_and_price” (number)

    I want to output like that

    For each representation i want to show the date then add a select list when selected it show the place_and_price dynamically.

    There is my code

    
    <?php if(get_field('representation')): ?>
    	<?php while(has_sub_field('representation')): ?>
     
    		<input type="checkbox"  id="<?php echo $i ;?>" name="date[]" value="<?php the_sub_field('date_where'); ?>" /><?php the_sub_field('date_where'); ?> - <?php the_sub_field('lieu_concert'); ?>
                
               <?php 
     
    		// vars
    		$select = get_sub_field_object('categorie_age');
    		$value = get_sub_field('categorie_age');
    		?>
    		<select name="sele-personne">
    			<?php foreach( $select['choices'] as $k => $v ): ?>
    				<option>
    					<?php if( $k == $value ): ?>
    						<span class="selected">Selected!</span>
    					<?php endif; ?>
    					<?php echo $v ; ?>
    				</option>
    			<?php endforeach; ?>
    		</select>
            
            <!-- how to show the value place and price dynamically depend with value is selected -->
              
      <?php endwhile; ?>
    <?php endif; ?>	

    Thanks in advance for your help, i’m trying to do my best for the english 🙂

    Have a very nice day

  • Hi @debosset

    I don’t quite understand what you mean by show the date then add a select list when selected it show the place_and_price dynamically.

    Do you mean that when you tick the checkbox with name date[], the select field will appear next to it?

    If so, this is not a question for the ACF Forum, but for a general Javascript and HTML forum such as stackoverflow.

    Does the above code produce the correct HTML?

    Thanks
    E

  • Hi thanks for your answer it’s kind of acf problem because i don’t know how to get the field that is number with the select field

    `<?php if(get_field(‘representation’)): ?>
    <?php while(has_sub_field(‘representation’)): ?>

    <input type=”checkbox” id=”<?php echo $i ;?>” name=”date[]” value=”<?php the_sub_field(‘date_where’); ?>” /><?php the_sub_field(‘date_where’); ?> – <?php the_sub_field(‘lieu_concert’); ?>

    <?php

    // vars
    $select = get_sub_field_object(‘categorie_age’);
    $value = get_sub_field(‘categorie_age’);
    ?>
    <select name=”sele-personne”>
    <?php foreach( $select[‘choices’] as $k => $v ): ?>
    <option>
    <?php if( $k == $value ): ?>
    <span class=”selected”>Selected!</span>
    <?php endif; ?>
    <?php echo $v ; ?>
    </option>
    <?php endforeach; ?>
    </select>

    <!– It doesn’t work … –>
    <input type=”texte” readonly value=”<?php the_sub_field(‘place_and_price’); ?>” />
    <!– It doesn’t work … –>
    <?php endwhile; ?>
    <?php endif; ?>

    
    
    this is my result :
    
    

    <input type=”checkbox” id=”1″ name=”date[]” value=”Samedi 14 Décembre 2013, 20h”> Samedi 14 Décembre 2013, 20h

    <select name=”sele-personne”>
    <option>
    Cat 1 – Adulte
    </option>
    <option>
    Cat 2 – Adulte
    </option>
    <option>
    Cat 3 – Adulte
    </option>
    <option>
    Cat 1 – Etudiant
    </option>
    <option>
    Cat 2 – Etudiant
    </option>
    <option>
    Cat 3 – Etudiant
    </option>
    <option>
    Cat 1 – Enfant
    </option>
    <option>
    Cat 2 – Enfant
    </option>
    <option>
    Cat 3 – Enfant
    </option>
    </select>

    <input type=”texte” id=”place_and_price” readonly value=”” />
    <!– i want when i select a item to get the sub_filed (place_and_price) in the input –>
    `

    This how it is in the admin

    You can add a categorie -> exemple Cat – Adulte then the price for it place_and_price 20 $

    But here on my result i don’t see the price the input is still empty ( i would know how to get it and load correctly with the categorie i have selected

    thanks in advance

  • I did a jsfiddle of my code (in case above i change the term so it sound like in english…)

    http://jsfiddle.net/UK5fZ/

  • I don’t need option page but it may be something like this?

    I don’t know how to make it work 🙁

    This is my jsfiddle corrected for the basic js

    http://jsfiddle.net/UK5fZ/1/

  • Hi @debosset

    Am I correct in assuming your question is this:
    i don’t know how to get the field that is number with the select field

    Can you please better describe this issue?

    Perhaps you could read over the has_sub_field or have_rows or repeater field documentation articles?

    Your code is far to complex for me to offer any free ACF support, perhaps you can be very specific as to what you need help with, as I can’t provide the time to debug your entire code to understand what does and doesn’t work.

    Thanks
    E

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

The topic ‘Problem with a repeater field (select + number field)’ is closed to new replies.