I've finally got this working thanks to many of the posts in the forum for this extension, especially Aceman3000 who put me on the trail of creating a json.php. However, using that, as specified by Aceman, gives me a dropdown with three lines for each potential match as you might expect from his code which specifies that id, label, and value be echoed.
What I'd like to do is display just the label much like more traditional, HTML-generated dropdowns with the id and value hidden behind it. Unfortunately, my jQuery/JavaScript skills are about zilch. Can anyone help me with how to achieve that?
Leave a comment
Please only use comments to help explain the above extension. If you have any questions, please ask in the forum instead.
FIx that works for me
In the file TagView.php, delete the line
$jui=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.vendors.jui').'/js/jquery-ui.min.js');
And replace
with
$cs->registerCoreScript('jquery.ui');
My fix
replace all into
$tag_it_js=Yii::app()->getAssetManager()->publish($tag_it.'/tag-it.js'); $tag_it_css=Yii::app()->getAssetManager()->publish($tag_it.'/tag-it.css'); Yii::app()->clientScript //->registerCoreScript('jquery') FIX ->registerCoreScript('jquery.ui') ->registerScriptFile($tag_it_js) ->registerCssFile($tag_it_css) ->registerScript($id,' $("#'.$id.'").tagit({ tags: '.$tags.', url: "'.$url.'" }); ', CClientScript::POS_READY);
$tag_it - it`s my variable from widget
public function run() { $this->tags = json_encode($this->tags); // this method is called by CController::endWidget() $this->render('TagView', array( 'id' => $this->id, 'tags' => $this->tags, 'url' => $this->url, 'tag_it' => dirname(__FILE__), 'title' => $this->title, )); }
Formatting the dropdown
I've finally got this working thanks to many of the posts in the forum for this extension, especially Aceman3000 who put me on the trail of creating a json.php. However, using that, as specified by Aceman, gives me a dropdown with three lines for each potential match as you might expect from his code which specifies that id, label, and value be echoed.
[<?php if($tags){ $total = count($tags) - 1; foreach ($tags as $i =>$tag){ //echo $tag->name; echo '{'; echo '"id": "'.$tag->id.'",'; echo '"label": "'.$tag->name.'",'; echo '"value": "'.$tag->name.'"'; echo '}'; if($total !== $i){ echo ','; } } }?>]
What I'd like to do is display just the label much like more traditional, HTML-generated dropdowns with the id and value hidden behind it. Unfortunately, my jQuery/JavaScript skills are about zilch. Can anyone help me with how to achieve that?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.