I’m having difficulties in writing javascript in yii view files.
For example:
<?php Yii::app()->clientScript->registerScript('id', '$("#idselect").jqGrid({
..lots of option here
});'); ?>
In the above example, i have to write the script inside registerScript method call. This is annoying, because I lost my IDE formatting ability.
Another example:
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'nomorOp'
,'sourceUrl' => $this->createUrl('pengiriman/searchOp')
,'options' => array(
'select' => 'js:function(event, ui) {
$("#orderPembelianId").val(ui.item.value);
return false;
}'
,'focus' => 'js:function(event, ui) {
var start = $(this).val().length;
$(this).val(ui.item.label);
var end = ui.item.label.length;
setCaretSelection(this, start, end);
return false;
}'
,'change' => 'js:function(event, ui) {
if(ui.item == undefined) {
$(this).val("");
$("#orderPembelianId").val("");
}
}'
,'autoFocus' => true
)
,'value' => ($model->orderPembelian != null ? $model->orderPembelian->nomor : '' )
)); ?>
As you can see above, I need to insert a javascript function callback in the option. This is also annoying.
Is there any ways to avoid these? Do I really need to use registerScriptFile instead?
What is the best way to write javascript?
I’m sorry if this is a silly question… I’m still new in Yii…
Thanks for the advice…