Home › Forums › ACF PRO › Copy relationship field values to another relationship field › Reply To: Copy relationship field values to another relationship field
Nevermind, I solved the problem in a much easier way.
In case someone else needs a similar solution, here is the code for solution:
jQuery(document).ready(function($){
function ivab_copy_field_values(source_field_id, target_field_id) {
$(source_field_id).find('.values li input').each(function() {
fieldValue = $(this).val();
targetLi = $(target_field_id).find('.choices li span[data-id="'+fieldValue+'"]');
if ($(targetLi).length) {
$(targetLi).trigger('click');
}
});
}
if ($('#normal-sortables').length) {
$('.acf-field-56c3703fffcbd .acf-label')
.append('<button class="button button-large copybutton" type="button" data-targetfield="#acf-field_56c3703fffcbd" data-sourcefield="#acf-field_56c372ebcec74">Copy from B side</button>');
$('.copybutton').on('click', function() {
console.log($(this));
sourceField = $(this).attr('data-sourcefield');
targetField = $(this).attr('data-targetfield');
ivab_copy_field_values(sourceField, targetField);
});
}
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.