Home › Forums › General Issues › Logic between number and relationship fields › Reply To: Logic between number and relationship fields
Found a solution, reworked my code as the following:
jQuery(document).ready(function($) {
if (typeof acf === 'undefined') { return; }
var featuredContentExtension = acf.ajax.extend({
events: {
'change [data-key="field_5798cf2592b92"]': '_state_change'
},
_state_change: function(e) {
var select_field = $('#acf-field_5798ced492b91');
var number_field = $('#acf-field_5798cf2592b92');
var element = $('.acf-relationship');
var field_acf_data = acf.get_data( element );
var new_post_number = number_field.val();
select_field.attr('data-max', "[\"" + new_post_number + "\"]");
field_acf_data.max = new_post_number;
}
});
});
The key here was to retrieve the ACF data from the element using the acf.get_data
method, passing the relationship element as parameter 😉
Thanks for your attention !
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.