Today I needed to add autocomplete to a field that could contain comma separated usernames and obviously the requirements included autocomplete. I thought this problem must be solved already in the ecosystem and sure, Views has it already. So I have added '#autocomplete_path' => 'admin/views/ajax/autocomplete/user', '#element_validate' => array('my_module_usernames_validate')
and then
<?php
function my_module_usernames_validate(&$element) {
if ($values = drupal_explode_tags($element['#value'])) {
// Good thing Views doesn't use the native constructor.
$handler = new views_handler_filter_user_name();
// And this function doesn't use the object at all.
$handler->validate_user_strings($element, $values);
}
}
?>
Ps. This has been confirmed as working (with a plugin instance) in D8 too.
Commenting on this Story is closed.