Commit 082ba8a2 by Crisu83

improved typeahead (fixes #115)

parent 9a8b1cb2
......@@ -1342,6 +1342,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<div class="well">
<?php $this->widget('bootstrap.widgets.TbTypeahead', array(
'name'=>'typeahead',
'options'=>array(
'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,
......@@ -1357,6 +1358,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbTypeahead', array(
'options'=>array(
'name'=>'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) {
......
......@@ -11,16 +11,12 @@
/**
* Bootstrap type-a-head widget.
*/
class TbTypeahead extends CWidget
class TbTypeahead extends CInputWidget
{
/**
* @var array the options for the Bootstrap JavaScript plugin.
*/
public $options = array();
/**
* @var array the HTML attributes for the widget container.
*/
public $htmlOptions = array();
/**
* Initializes the widget.
......@@ -39,9 +35,20 @@ class TbTypeahead extends CWidget
*/
public function run()
{
$id = $this->id;
list($name, $id) = $this->resolveNameID();
if (isset($this->htmlOptions['id']))
$id = $this->htmlOptions['id'];
else
$this->htmlOptions['id'] = $id;
if (isset($this->htmlOptions['name']))
$name = $this->htmlOptions['name'];
echo CHtml::tag('input', $this->htmlOptions);
if ($this->hasModel())
echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
else
echo CHtml::textField($name, $this->value, $this->htmlOptions);
$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->clientScript->registerScript(__CLASS__.'#'.$id, "jQuery('#{$id}').typeahead({$options});");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment