Silverstripe自动完成文本字段

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).

enter image description here

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';
}

I just checked out the source code and the default displayField is Title. You can either change your UserCompany object by changing the CompanyName field to Title or use the setDisplayField method.

$fields->push(AutoCompleteField::create('StudentGroup_Name', 'Company name *','',null,null,'UserCompany','CompanyName')->setDisplayField('CompanyName')->setAttribute('required','required'));

Edit

Using a setter function for Title should work also. That means you don't need to use setDisplayField.

class UserCompany extends DataObject {
  ...

  function Title() {
    return $this->CompanyName;
  }
}