Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
Yii Bootstrap 3
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Common
Yii Bootstrap 3
Commits
082ba8a2
Commit
082ba8a2
authored
Jul 29, 2012
by
Crisu83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved typeahead (fixes #115)
parent
9a8b1cb2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
index.php
demo/protected/views/site/index.php
+2
-0
TbTypeahead.php
widgets/TbTypeahead.php
+14
-7
No files found.
demo/protected/views/site/index.php
View file @
082ba8a2
...
...
@@ -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) {
...
...
widgets/TbTypeahead.php
View file @
082ba8a2
...
...
@@ -11,16 +11,12 @@
/**
* Bootstrap type-a-head widget.
*/
class
TbTypeahead
extends
CWidget
class
TbTypeahead
extends
C
Input
Widget
{
/**
* @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
}
);"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment