yiisoft/yii — pull request #782 by ianare (2012-06-04 16:42:50+00:00)
Title: add selector option to htmlOptions

Here is a patch to allow using a 'selector' option to an ajax-enabled widget.

The reason is that in some cases we need to select by class rather than ID in order to work with elements added by ajax calls.

It could be also in other situations also, which is why I used a free-form selector field rather than a 'class' field ...

Here is an example use:

echo CHtml::ajaxButton('label', 'http://example.com',
array('beforeSend' => 'js:function(){alert("hello");}'),
array(
'class' => 'btn-delete-event',
'selector' => '.btn-delete-event'
)
);

... and the JS generated (made pretty for legibility):

$('body').on('click','.btn-delete-event',function(event){
jQuery.ajax({
'beforeSend':function(){
alert("hello");
},
'url':'http://example.com',
'cache':false
});
return false;
});