Yii Framework Forum: Yiibooster Typeahead Won't Work. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yiibooster Typeahead Won't Work. yiibooster typeahead sinppet won't work Rate Topic: -----

#1 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 08-May 12

Posted 15 November 2012 - 10:44 PM

$this->widget('bootstrap.widgets.TbTypeahead', array(
    'options'=>array(
    'name'=>'demo-typeahead',
    'source'=>array(
    'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
    'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
    'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
    'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
    'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri',
    'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
    'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio',
    'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
    'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
    'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'),
    'items'=>4,
    'matcher'=>"js:function(item) {
    return ~item.toLowerCase().indexOf(this.query.toLowerCase());
    }",
    )));


I 've got this error "TbTypeahead must specify "model" and "attribute" or "name" property values.".Any ideas,Thx.
0

#2 User is offline   Giuseppe Santoro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 15-October 12

Posted 16 November 2012 - 03:21 AM

Hi nakarin,
assuming that you want to use a form to create/update the "state" of a "user", you should have a model "User" with an attribute "state", so you should specify the model and the state.

$this->widget('bootstrap.widgets.TbTypeahead', array(
    'model'     => $model,  // INSTANCE OF MODEL 'User'
    'attribute' => 'state', // ATTRIBUTE
    'options'=>array(
        'name'=>'demo-typeahead',
        'source'=>array(
        'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
        'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
        'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
        'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
        'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri',
        'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
        'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio',
        'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
        'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
        'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'),
        'items'=>4,
        'matcher'=>"js:function(item) {return ~item.toLowerCase().indexOf(this.query.toLowerCase());}",
        )
    )
);


Otherwise you should specify just a name for this widget.

$this->widget('bootstrap.widgets.TbTypeahead', array(
    'name'     => 'your-name-for-the-widget',  // NAME
    'options'=>array(
        'name'=>'demo-typeahead',
        'source'=>array(
        'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
        'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
        'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
        'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
        'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri',
        'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
        'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio',
        'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
        'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
        'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'),
        'items'=>4,
        'matcher'=>"js:function(item) {return ~item.toLowerCase().indexOf(this.query.toLowerCase());}",
        )
    )
);


For future posts, please use the tag [code] to format your code ;).
1

#3 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 08-May 12

Posted 16 November 2012 - 04:46 AM

Thank you very much Giuseppe Santoro.Work like a charm. :)

View PostGiuseppe Santoro, on 16 November 2012 - 03:21 AM, said:

Hi nakarin,
assuming that you want to use a form to create/update the "state" of a "user", you should have a model "User" with an attribute "state", so you should specify the model and the state.

$this->widget('bootstrap.widgets.TbTypeahead', array(
    'model'     => $model,  // INSTANCE OF MODEL 'User'
    'attribute' => 'state', // ATTRIBUTE
    'options'=>array(
        'name'=>'demo-typeahead',
        'source'=>array(
        'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
        'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
        'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
        'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
        'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri',
        'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
        'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio',
        'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
        'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
        'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'),
        'items'=>4,
        'matcher'=>"js:function(item) {return ~item.toLowerCase().indexOf(this.query.toLowerCase());}",
        )
    )
);


Otherwise you should specify just a name for this widget.

$this->widget('bootstrap.widgets.TbTypeahead', array(
    'name'     => 'your-name-for-the-widget',  // NAME
    'options'=>array(
        'name'=>'demo-typeahead',
        'source'=>array(
        'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
        'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
        'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
        'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
        'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri',
        'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
        'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio',
        'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
        'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
        'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'),
        'items'=>4,
        'matcher'=>"js:function(item) {return ~item.toLowerCase().indexOf(this.query.toLowerCase());}",
        )
    )
);


For future posts, please use the tag [code] to format your code ;).

0

#4 User is offline   venuk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 15-February 13

Posted 15 February 2013 - 08:49 PM

how to populate TBtypeahead with database column values than static data?

appreciated in advance for your great help
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 16 February 2013 - 05:14 AM

/* moved from General Discussion */
"Less noise - more signal"
0

#6 User is offline   gunnit 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-June 12

Posted 28 May 2013 - 05:15 AM

View Postjacmoe, on 16 February 2013 - 05:14 AM, said:

/* moved from General Discussion */

moved to where ???? i can't find the continuation to this topic , is there one ?
0

#7 User is offline   GoofyX 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 15-April 09
  • Location:Thessaloniki, Greece

Posted 08 September 2013 - 07:20 AM

This is an old thread, but I have problems implementing the Bootstrap typeahead component populated by ajax call.

Here is the code for the widget:

	$this->widget('bootstrap.widgets.TbTypeahead', array(
		'model'=>$expense,
		'attribute'=>'afm',
		'htmlOptions'=>array('autocomplete'=>'off'),
		'options'=>array(
			'source'=>'js:function(query, process) {
				$.ajax({url: "' . $urlAfm . '", data: {query: query}, dataType: "json" })
				.done(function(data) {
					return process(data);
				})}',
		)));
	?>


The code from the controller action that returns the JSON data is:

	public function actionAjxGetAFM($query = '') {
		if (Yii::app()->request->isAjaxRequest && trim($query) != '') {
			$companies = Yii::app()->db->createCommand('SELECT name FROM company WHERE afm '
				. 'LIKE :match LIMIT 10')->queryColumn(array(':match'=>$query . '%'));
			Yii::trace(print_r(CJSON::encode($companies), true));
			echo CJSON::encode($companies);
			Yii::app()->end();
		}
		echo '0';
	}

I can see from Firebug, that the AJAX call is fired and I can also see the JSON response. However, no popup menu appears to select any item.

What am I doing wrong?
... Morpheus: What is "real"? How do you define "real"? If you 're talking about what you can feel, what you can smell, what you can taste and see, then "real" is simply electrical signals interpreted by your brain...
0

#8 User is offline   GoofyX 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 15-April 09
  • Location:Thessaloniki, Greece

Posted 01 October 2013 - 11:30 AM

I found the following article explains things pretty well:

http://tatiyants.com...trap-typeahead/
... Morpheus: What is "real"? How do you define "real"? If you 're talking about what you can feel, what you can smell, what you can taste and see, then "real" is simply electrical signals interpreted by your brain...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users