Yii Framework Forum: Using JS functions with string parameters in click for CGridView button - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using JS functions with string parameters in click for CGridView button Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 December 2010 - 06:19 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 December 2010 - 06:30 AM

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

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

Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 December 2010 - 06:32 AM

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

http://www.yiiframew...#buttons-detail

Quote

'click'=>'...', // a JS function to be invoked when the button is clicked

Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 December 2010 - 06:37 AM

View Postmdomba, on 15 December 2010 - 06:32 AM, said:

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

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).
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#5 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 15 December 2010 - 06:49 AM

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).
0

#6 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 December 2010 - 07:39 AM

View Postzaccaria, on 15 December 2010 - 06:49 AM, said:

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

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! :}
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users