Support

Account

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 !