HOW TO create form fields with autocomplete option?

Discuss everything related to ApPHP Durecty CMF. All versions. Any questions related to the Directy CMF developing or using should be posted to this forum.

Moderators: alexandrleonenko, alexmst

administrator
Site Admin
Site Admin
Posts: 6169
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO create form fields with autocomplete option?

Postby administrator » May 20th, '16, 14:12

When you use CGridView widget you may use autocomplete in filtering fields or in add/edit mode form fields.

The main idea is : the widget defines some JavaScript event that's called when you change on enter something and call to the Controller/Action you define.
This Controller/Action returns a search result, that will be shown in dropdown box for selection.
Let's see an examples.

Example 1. Search by country name and using selected value as countryID.

Code: Select all

'filters'=>array(
'id'  => array('title'=>A::t('app', 'Name'), 'table'=>CConfig::get('db.prefix').'countries', 'type'=>'textbox', 'operator'=>'like%', 'width'=>'140px', 'maxLength'=>'', 'autocomplete'=>array('enable'=>true, 'ajaxHandler'=>'Ajax/getLocations', 'minLength'=>2, 'returnId'=>true)),
),


Example 2. Search by country name and using selected value as country name.

Code: Select all

'filters'=>array(
'name'  =>  array('title'=>A::t('app', 'Name'), 'type'=>'textbox', 'operator'=>'like%', 'width'=>'140px', 'maxLength'=>'', 'autocomplete'=>array('enable'=>true, 'ajaxHandler'=>'Ajax/getLocations', 'minLength'=>2, 'returnId'=>false)),
),


The difference in these two samples is in using 'returnId'=>true or 'returnId'=>false.

Code: Select all

'autocomplete'=>array('enable'=>true, 'ajaxHandler'=>'Ajax/getLocations', 'minLength'=>2, 'returnId'=>true)

Return to “ApPHP Directy CMF {developers/users}”