Support

Account

Home Forums Backend Issues (wp-admin) ACF Javascript API – Dynamically Update select2 Field Options Reply To: ACF Javascript API – Dynamically Update select2 Field Options

  • The hook acf.addAction('select2_init', function( $select, args, settings, field ){ is perfect and it would allow me to assign the correct language settings to all fields by using args['language'] = 'xx'; and by integrating this

    $.fn.select2.amd.define('select2/i18n/xx',[],function () {
      return {
        errorLoading: function () {
          return acf.__('the results could not be loaded.');
        },
        inputTooLong: function (args) {
          var overChars = args.input.length - args.maximum;
    
          var message = acf.__('please delete') + ' ' + overChars + ' ' + acf.__('character');
    
          if (overChars != 1) {
            message += 's';
          }
    
          return message;
        },
        inputTooShort: function (args) {
          var remainingChars = args.minimum - args.input.length;
    
          var message = acf.__('please enter') + ' ' + remainingChars + ' ' + acf.__('or more characters');
    
          return message;
        },
        loadingMore: function () {
          return acf.__('loading more results…');
        },
        maximumSelected: function (args) {
          var message = acf.__('you can only select') + ' ' + args.maximum + ' ' + acf.__('item');
    
          if (args.maximum != 1) {
            message += 's';
          }
    
          return message;
        },
        noResults: function () {
          return acf.__('no results found');
        },
        searching: function () {
          return acf.__('searching...');
        },
        removeAllItems: function () {
          return acf.__('remove all items');
        },
        removeItem: function () {
          return acf.__('remove item');
        },
        search: function() {
          return acf.__('search');
        }
      };
    });

    but the new problem is that now all select2 fields have more hight than before – it seems that they lost the styling…….