I used tractorcow's Silverstripe-autocomplete module on a website to implement autocomplete feature on a textfield. However, I wonder why it returns the ID field instead of text(on CompanyName field).
Here's the code.
On my page I used it on a form as:
public function MyForm(){
$fields = FieldList::create();
...
$fields->push(AutoCompleteField::create('StudentGroup_Name', 'Company name *','',null,null,'UserCompany','CompanyName')->setAttribute('required','required'));
...
}
then, my dataobject is as follows:
class UserCompany extends DataObject{
private static $db = [
'CompanyID' => 'Int',
'CompanyName' => 'Varchar(512)'
];
private static $summary_fields = [
'CompanyID' => 'CompanyID',
'CompanyName' => 'CompanyName'
];
private static $default_sort = 'CompanyName ASC';
}