sebas
(Sebathi)
November 7, 2008, 2:41pm
1
Hi! I'm testing yii and make some test.
In my test i've 3 ajaxLinks that update a div. When i update it with an autocomplete widget, i didn't include the scripts needed. How do i do that?
Something like using scripts to import them to the page.
Thx!
Sebas
notzippy
(Notzippy)
November 7, 2008, 3:39pm
2
You mean something like ?
$this->clientScript->registerScriptFile(Yii::app()->baseUrl.'/scripts/jquery-ui.js');
sebas
(Sebathi)
November 7, 2008, 3:53pm
3
mmm, yes and no.
I know that i can do that, but i think that maybe sometime you could update your script and it's better if we have a CAutocomplete, there must be a way to import the script from CAutocomplete. Something like CAutocomplete::ensureScriptImport() or something like that.
It's just an idea.
sebas
(Sebathi)
November 7, 2008, 4:20pm
4
I found another way:
In my layout file (or in any controller instance file)
<?$this->getClientScript()->registerCoreScript('autocomplete');
$this->getClientScript()->registerCssFile($this->getClientScript()->getCoreScriptUrl().'/autocomplete/jquery.autocomplete.css');
?>
but Css file registration still needs that i know where it is.
I think it's better a way to register the css from a function at the widget like
CWidget::registerCss();
What do you think?
notzippy
(Notzippy)
November 7, 2008, 4:30pm
5
The CAutocomplete does register its script internally -
(Any widget should do the same)
If you are adding the autocomplete using an ajax update you need to set the last parameter of render partial to true.
z
sebas
(Sebathi)
November 7, 2008, 6:09pm
6
So i can’t make it work.
I tried:
public function actionAutocompleteUsername(){
return $this->renderPartial("autocomplete",null, false, true);
}
and also
public function actionAutocompleteUsername(){
return $this->renderPartial("autocomplete",null, true);
}
My index.php view is:
<?php echo CHtml::ajaxLink ("Ayuda" , $this->createUrl("autocomplete/AutocompleteUsername"),
array('update'=>'.mainBody'))?>
<div class="mainBody">
</div>
Then, the autocomplete.php view is:
<?php echo CHtml::form();?>
<?php $this->widget('CAutoComplete',array('name'=>'username',
'max'=>10,
'delay'=>750,
'matchCase'=>false,
'url'=>$this->createUrl("autocomplete/autocomplete"),
'minChars'=>0,
'autoFill'=>true,
)
); ?>
<?php echo CHtml::ajaxSubmitButton("Buscar", array('showData'), array('update'=>".user_data")); ?>
</form>
<div class="user_data">
</div>
The ajaxbutton didn't work neither.
Any ideas?
qiang
(Qiang Xue)
November 7, 2008, 7:03pm
7
Just fixed this issue. Thanks.
sebas
(Sebathi)
November 7, 2008, 8:37pm
8
The autocomplete works now, but the AjaxButton is not submiting anything.
notzippy
(Notzippy)
November 7, 2008, 8:53pm
9
The ajaxButton by itself will not, unless you use the ajaxSubmitButton (or add the type="post" to the ajax options.
qiang
(Qiang Xue)
November 7, 2008, 9:19pm
10
I just checked in a fix. This is due to the duplication of automatically generated button id.
sebas
(Sebathi)
November 8, 2008, 2:34am
11
Something is still wrong.
If i do this:
<?php echo CHtml::form();?>
<?php $this->widget('CAutoComplete',array('name'=>'username',
'max'=>10,
'delay'=>750,
'matchCase'=>false,
'url'=>$this->createUrl("autocomplete/autocomplete"),
'minChars'=>0,
'autoFill'=>true,
)
); ?>
<?php echo CHtml::ajaxSubmitButton("Buscar2",$this->createUrl("autocomplete/showData"),
array('update'=>".user_data"),
array('id'=>'boton2')); ?>
<?php echo CHtml::ajaxSubmitButton("Buscar1",$this->createUrl("autocomplete/showData2"),
array('update'=>".user_data")); ?>
</form>
<div class="user_data">
</div>
[code]
only works diferent when i pass the id attribute in htmlOptions array.
so, in some place the documentation must say that the id must be passed...
or make it work that is better
qiang
(Qiang Xue)
November 8, 2008, 2:41am
12
Did you use my latest check-in? It already generates an id if it is not present.
sebas
(Sebathi)
November 9, 2008, 1:58pm
13
yes, I have the last update.
It generates the same id for the 2 buttons like this:
<link rel="stylesheet" type="text/css" href="/pruebaYii/assets/ffaee85e/autocomplete/jquery.autocomplete
.css"/>
<script type="text/javascript" src="/pruebaYii/assets/ffaee85e/jquery.js"></script>
<script type="text/javascript" src="/pruebaYii/assets/ffaee85e/jquery.bgiframe.js"></script>
<script type="text/javascript" src="/pruebaYii/assets/ffaee85e/jquery.dimensions.js"></script>
<script type="text/javascript" src="/pruebaYii/assets/ffaee85e/jquery.ajaxqueue.js"></script>
<script type="text/javascript" src="/pruebaYii/assets/ffaee85e/jquery.autocomplete.js"></script>
<form action="/pruebaYii/index.php?r=autocomplete/autocompleteUsername&_=1226239083783" method="post"
><input id="username" type="text" value="" name="username"/><input name="button" type="button" value
="Buscar2" id="button"/><input name="button" type="button" value="Buscar1" id="button"/></form>
<div class="user_data">
</div><script type="text/javascript">
/*<![CDATA[*/
jQuery("#username").autocomplete("/pruebaYii/index.php?r=autocomplete/autocomplete",{'minChars':0,'delay'
:750,'matchCase':false,'autoFill':true,'max':10});
jQuery('#button').click(function(){jQuery.ajax({'type':'POST','url':'/pruebaYii/index.php?r=autocomplete
/showData','cache':false,'data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery
(".user_data").html(html)}});return false;});
/*]]>*/
</script>
there is 2 buttons with id="button" attribute.
qiang
(Qiang Xue)
November 9, 2008, 3:32pm
14
I see. Just checked in a fix. However, perhaps in your case you will need to explicitly specify the button 'name' (and/or 'id') to avoid id conflict.
imasia
(Paul Apostol)
June 10, 2009, 7:20pm
15
Not sure if already solved but I don't like the renderPartial with the last param true.
So, I've made an extension to load it under the base page (the page from where I'll open the ajax dialog box)
The widget call is:
$this->createWidget('application.extensions.AjaxHelper.Autocomplete');
and is:
class Autocomplete extends CAutoComplete
{
public function init()
{
$this->registerClientScript();
}
public function registerClientScript()
{
$cs=Yii::app()->getClientScript();
$cs->registerCoreScript('autocomplete');
if($this->cssFile!==false)
self::registerCssFile($this->cssFile);
}
}