Using JS functions with string parameters in click for CGridView button

Hi there,

I have two problems extending CButtonColumn and would appreciate any help as I found no solution in documentation. I’ve separated both problems into two topic as they are quite different and one post holding both of them become to long - no one would like to read it! :] So this is continuity to this post.

A terrible mess happens if I use below code, but I can’t find what is wrong with it?


'class'=>'CButtonColumn',

'template'=>'{down} {delete}',

'buttons'=>array

(

	'down' => array

	(

    	'label'=>'[-]',

    	'url'=>'"#"',

    	'visible'=>'$data->ID > 0',

    	'click'=>'alert("Going down!");',

	),

),

If I use the code exactly as in the example, the down button does not work and upon each page refresh I got JS error in the console, saying: “missing ) after argument list - jQuery(’#zlecenia-grid a.down’).live(‘click’,alert(“Going down!”)”.

If I remove ; after closing braced, even stranger things happens - I see that alert upon page refresh, not after click, and my JS console gots error saying: "b is undefined in assets/418d6bd7/jquery.min.js line: 49".

And the strangest part is that errors in down button declaration are also influencing delete button. I.e. clicking it shows my own controller-error suggesting that delete request was sent in GET while it has to be sent in POST. This is really weird, as I do not changed delete button declaration even a bit and was surprised that one button can influence another one.

As jQuery is used… you need to put the js "click" code in a function… like:




  	'click'=>'function(){alert("Going down!");}',



I just checked the documentation and maybe it’s not obvious on the first read… but it says so:

http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail

It says exactly, what it says. There is not even a word about jQuery, there is specifically written JS. alert is a JS code, while in jQuery I have to use what you provided (thank you!) - function(){alert("Going down!");} - which is obvious if only there would a clear explanation in documentation, that jQuery, not JS code should be provided (or a JS code surrounded by jQuery function call to be precisely).

The documentation is clear, it says js function because a callback is needed.

This function is a js function, there is nothing of specific of jquery, the point here is that is needed a valid callback.

Anyway some more example in the documentation should help many people, or some chapither in the definitive explaining how to write this callbacks (I learned by reading the Yii generated js code).

For me it wasn’t clear, but you have your right to state something opposite! :] And let’s end discussion here, before we go far too off-topic! :}