Problem with autocomplete of tag it widget(http://con.cept.me/blog/post/2/yii-tag-it-widget )
No suggestions are displayed when enter a tag which is already there in database.
Autocomplete Controller
/**
* Autocomplete for tag widget
*/
public function actionJson(){
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$this->layout = false;
if(isset($_GET['tag'])){
$c=$_GET['tag'];
$criteria=new CDbCriteria(array(
'limit' => 10
));
$criteria->addSearchCondition('name', $c);
$tags = Tags::model()->findAll($criteria);
$this->render('json', array('tags' => $tags));
}
}
Widget code in _fom.php view
<?php $this->widget('application.components.widgets.tag.TagWidget', array(
'url'=> Yii::app()->request->baseUrl.'/tags/json/',
'tags' => $model->getTags(),
));
?>
json.php
[<?php if($tags){
$total = count($tags) - 1;
foreach ($tags as $i =>$tag){
echo '{';
echo '"id": "'.$tag->id.'",';
//echo '"label": "'.$tag->tag.'",';
echo '"value": "'.$tag->name.'"';
echo '}';
if($total !== $i){
echo ',';
}
}
}?>]
Where am I going wrong
jayant
(Codesutras)
July 11, 2013, 12:25pm
#2
Problem with autocomplete of tag it widget(http://con.cept.me/blog/post/2/yii-tag-it-widget )
No suggestions are displayed when enter a tag which is already there in database.
Autocomplete Controller
/**
* Autocomplete for tag widget
*/
public function actionJson(){
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$this->layout = false;
if(isset($_GET['tag'])){
$c=$_GET['tag'];
$criteria=new CDbCriteria(array(
'limit' => 10
));
$criteria->addSearchCondition('name', $c);
$tags = Tags::model()->findAll($criteria);
$this->render('json', array('tags' => $tags));
}
}
Widget code in _fom.php view
<?php $this->widget('application.components.widgets.tag.TagWidget', array(
'url'=> Yii::app()->request->baseUrl.'/tags/json/',
'tags' => $model->getTags(),
));
?>
json.php
[<?php if($tags){
$total = count($tags) - 1;
foreach ($tags as $i =>$tag){
echo '{';
echo '"id": "'.$tag->id.'",';
//echo '"label": "'.$tag->tag.'",';
echo '"value": "'.$tag->name.'"';
echo '}';
if($total !== $i){
echo ',';
}
}
}?>]
Where am I going wrong
$this->render('json', array('tags' => $tags));
replace this with
$this->renderPartial('json', array('tags' => $tags));
And then check. Also make sure that you are getting results in $tags.
Please try this and let me know what you got.
$this->render('json', array('tags' => $tags));
replace this with
$this->renderPartial('json', array('tags' => $tags));
And then check. Also make sure that you are getting results in $tags.
Please try this and let me know what you got.
I have replaced but no change .
jayant
(Codesutras)
July 11, 2013, 3:05pm
#4
Strange have you tried to debug the code with firebug…Is there any ajax request is triggering
arely.coca
(Anc Antik 5)
September 30, 2013, 8:59pm
#5
I have the same problem. I have debugged the json, the function and everything is sending the data, but not showing the little suggestions:c Any idea?
Ankit_Modi
(Ankit Modi)
October 1, 2013, 3:54am
#6
Hi I think you can write a foreach loop
echo "id:".$tag->tag."|label: ".$tag->tag."|value:" .$tag->slug.'
';
[b]
Note: [/b]last colon is start new line not in same line.
I am not sure it’s work or not.
arely.coca
(Anc Antik 5)
October 2, 2013, 4:38am
#7
Hi I think you can write a foreach loop
echo "id:".$tag->tag."|label: ".$tag->tag."|value:" .$tag->slug.'
';
[b]
Note: [/b]last colon is start new line not in same line.
I am not sure it’s work or not.
Hi, I actually had a foreach. It was a jquery.min route problem. Now is showing the suggestions but when i try clicking on it or down key for selection, the suggestions disapear without leting me select them. Is that a bug?
Ankit_Modi
(Ankit Modi)
October 2, 2013, 5:04am
#8
Hi, I actually had a foreach. It was a jquery.min route problem. Now is showing the suggestions but when i try clicking on it or down key for selection, the suggestions disapear without leting me select them. Is that a bug?
No that’s not any bug and sorry i post a code only one dropdown select not a multiselsect
have you get the data on browser console using json response?
arely.coca
(Anc Antik 5)
October 2, 2013, 4:49pm
#11
Also check this
it’s awesome.
Hi! Thanks for all the links. But coming back to the tag it. It seems that its working fine, I’m debugging the json and sending the correct info. The problem here is this: When i write any letter, the suggestions appear on a little dropdown, when I click, on any space, even inside the dropdown for select the word and make it a tag, it disapear. I have tried stopping the propagation but it keeps the same and there are no signs of errors :c On the script after writing a letter and the suggestions appear, in the code appears the lines:
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible">2 results are available, use up and down arrow keys to navigate.</span>
But it just don’t let me navigate because it disapears.
I actually like the widget but it’s driving me crazy the fact I can’t select the suggestion that I want. :c