Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have an issue on how to update fields on select change, in repeater fields using Javascript api.

I have and select object that pulls values from another post with Ajax and PHP, and i am getting values. But i would like to update fields, in my repeater fields in the row, with values. But i cannot target my fields, when select dropdown changes..

This is my code

$field.on("change", function(e) {
                    // ajax request
                    jQuery.ajax({
                        type: "POST",
                        dataType: 'text',
                        url: ajax_url,
                        data: {
                            action: 'call_update', //the action is set when you added wp_ajax_ at the beginning of this answer.
                            postId: value,
                            nonce: wp_nonce
                        },
                        success: function(response) {
                            data = JSON.parse(response);
                            success(data);
                        },
                        error: function(jqxhr, textStatus, errorThrown) {
                            console.log(errorThrown);
                        }
                    });

                });

And in my success method i would like to update repeater fields

function success(data) {
                //acf.doAction('new_field', data);
                //alert(data.title + data.images);
               
 var title = acf.getField('field_6144c465a849c');
                title.val(data.title);


                //repeater = acf.getField('field_6144c42ea849b');

                //let sub_fields = [];

                //repeater.children('td.acf-field').each((i, $el) => {
                //    sub_fields[i] = acf.getField($el);
                //})
                //// show sub fields                    
                //console.log(sub_fields);


            }


But how do i target subfields with javascript, i can only find how i target field by key, and then it updates all fields trough all repeater rows.

Regards Martin


What I have tried:

Tried to get fields by children in parent, and to use a filter method, acf own documentation is lagging on information on how to get subfields in repeater
Posted
Updated 22-Mar-22 6:20am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900