1

is it possible to set a default value in a multiple select (post object source) on a event (ex. onclick a js function calculate a value. This value is the option to set as selected)?

I use acf.add_action(‘ready’, …. to get value to set as selected. It works. But i don’t now how to set it.

Thanks in advance.

Ethan Hunt
  • 173
  • 4
  • 17

2 Answers2

2
$member_id = $view->member_id; // variable in script to be passed coming from object (could be any variable.)
add_filter('acf/load_field/name=visit_name',
     function($field) use ($member_id) { 
      /* the variable after 'use' ($member_id) indicates that it is the one to 'use' from the main script.  $field is coming from 'acf/load_field'.  */
     $field['default_value'] = $member_id;
     return $field;
 }
);
Haider Ali
  • 21
  • 6
0

You could set it this way:

document.getElementById('id_of_your_select_element').value=value_of_option_to_select;

Found it here: https://stackoverflow.com/a/10911660

Luckyfella
  • 557
  • 4
  • 14