Reputation: 183
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.
Upvotes: 2
Views: 5430
Reputation: 21
$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;
}
);
Upvotes: 2
Reputation: 662
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
Upvotes: 0