Hello,
I am having a difficulty trying to get widget’s id before displaying it. What I want to achieve is this:
[INPUT BOX]
[AJAX SUBMIT BUTTON]
CListView
I want user to write a message, press the ajax button so the message gets posted and the CListView updates. This is what I’ve tried:
...
<?php echo CHtml::ajaxSubmitButton('Post', Yii::app()->createUrl('main/createDataEntry')); ?>
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_dataEntry',
'template' => '{items}',
'updateSelector' => 'input' //Just for testing purposes
));
?>
But the updateSelector doesn’t work. If I try to set any other element - it works. Also, I have tried executing this:
$("input").click(function() {$.fn.yiiListView.update('yw0')});
it works then. So what I need to do, is get the ID of the widget, add a click handler to the button and then render the widget. The problem is, I can’t manage to do this. I can get the ID of widget like this:
$listView = $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_dataEntry',
'template' => '{items}',
));
$id = $listView->id;
?>
but the widget gets rendered at the moment of code execution. The CBaseController->widget has a third parameter, which when set to true, returns HTML of the widget to the variable, so I can output it when I want to. But that way I can’t get the ID of the widget.
Another solution would be to register the javascript after outputing it (and add a event handler to the button), but I am thinking maybe there’s a nicer way to do this?
Thank you