Support

Account

Home Forums Add-ons Repeater Field Repeater Row Values Via Javascript

Solving

Repeater Row Values Via Javascript

  • Hello is there anyway to get the repeater row values via javascript? I can’t get it via getElementByName since the field id/names are randomly created, I need it for real time updating of values.

    Thank you and I really appreciate your help.

  • There isn’t a lot of documentation on using JavaScript with ACF. There is this document https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/. Beyond this you’ll need to find examples of how other people have done this. I can remember several topics on this forum on the subject and you might be able to find those.

    The field keys if that’s what you’re talking about that look something like this field_12345677 are randomly generated, but this is what you need to use when targeting the field using JavaScript.

    I have some examples of using JS in a different way, by extending the acf object, but nothing that does what you’re looking for. But you can look at this to see how you can target the fields https://github.com/Hube2/acf-dynamic-ajax-select-example

  • noyram23, did you find any solution to this? I have a similar problem.

    Regards
    Pete

  • Needed this today and stumbled on this post.

    I’m dynamically changing things via select2_ajax_data based on other field values, so I needed the value of a different field in a repeater row.

    This is the idea. Works well enough.

    
    // $input is coming from select2_ajax_data filter,
    // so it's the current field input.
    var fields = acf.getFields(
    	{
    		key: 'my_field_key',
    		parent: $input.parents( '.acf-row' ),
    	}
    );
    
    if ( fields ) {
    	var value = fields.shift().val();
    }
    
  • Needed this again and my original solution didn’t work for some reason. I found an easier way using sibling instead of parents.

    
    // field is coming from select2_ajax_data filter,
    // so it's the current field.
    // Using $input was breaking because select2 puts the actual input outside of the row.
    var fields = acf.getFields(
    	{
    		key: 'my_field_key',
    		sibling: field.$el,
    	}
    );
    
    if ( fields ) {
    	var first = fields.shift();
    	var value = first ? first.val() : '';
    }
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.