Well after all I've decided to adopt an autocomplete function...
That's my solution, but i still need to write some code on /libraries/grocery_CRUD.php.
I don't like to edit this, i hope there's a way to make a plugin.
However
1st) I added this simple function at the end of the file:
protected function get_autocomplete_input($field_info,$value)
{
$this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS);
$this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS);
$value = !is_string($value) ? '' : str_replace('"',""",$value);
$extra_attributes = '';
if(!empty($field_info->db_max_length))
$extra_attributes .= "maxlength='{$field_info->db_max_length}'";
$input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />";
$input .= '<script> $(function() { var availableTags = [';
$options = $field_info->extras;
for($i = 0; $i < count($options); ++$i) {
$input .= '"'.$options[$i].'"';
if ($i != count($options)-1) $input .= ', ';
}
$input .= "]; $( '#field-{$field_info->name}' ).autocomplete({ source: availableTags, minLength: 0 }); });</script>";
return $input;
}
2nd) Then, in the function get_field_input (line 216) I added 'autocomplete' to the array $types_array.
3rd) Then I edited the function function change_list_value($field_info, $value = null) (line 257)
the original code was:
case 'dropdown':
$value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value;
break;
now it is:
case 'autocomplete':
case 'dropdown':
$value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value;
break;
You can use it in you controller like this:
$crud->field_type('nome', 'autocomplete', array('0'=>'Pippo','1'=>'Pluto'));
... and that's the result:
I hope you enjoy it ;)
PS: i used minLength: 0 in the function get_autocomplete_input, because I have few values to choose, if you have many, you can use minLength: 1