The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Adding comma separated username autocomplete to a D7 form

Submitted by nk on Mon, 2014-11-17 21:20

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.