CStarRating remove vote

If you push on it , it writes




e.nodeName is undefined

[Break On This Error] (function(a,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />{function cy(a){return f...h]&&f.event.trigger(c,d,b.handle.elem 



example here http://www.yiiplayground.cubedwater.com/index.php?r=UiModule/ui_other/starRating

  • open firebug to see

Some one can explain how to implement it? or I should write my own functino for it?

This has already being asked here - http://www.yiiframework.com/forum/index.php?/topic/22180-cstarrating-problem-with-118/

I just spent a bit on debugging this error with firebug and found what is the problem.

In the playground example this line is used in the callback -


data: "'.Yii::app()->request->csrfTokenName.'='.Yii::app()->request->getCsrfToken().'&rate=" + $(this).val() 

The callback function is called every time a "star" is clicked… but even when the "remove vote" is clicked…

At the time when you click the "remove vote" $(this) is not any more the input of the stars but the button itself (a link)… and this one does not have a value… so at that time $(this).val() fires an error in jQuery

Thx for the response… actually I figured that out yesterday…

this is yii playground issue http://code.google.com/p/yiiplayground/issues/detail?id=2

The way I solved it was to put try catch…


try{

 var abrakadabra = $(this).val();

 // submit rating...

}catch(err){

// submit rating cancel...

}



This is very dirty solution… but I was not able to retrive $(this) parents or closest div or something that will make it possible to somhow figure out if it has value or not directly…

Maybe in the future I will fight with it more to make it cleaner… just not wanted to waste more time on that issue… and the try catch was the simplest way…

maybe just type of .attr("value") !== undefined could solve it, or check if it is numeric… maybe actually I will give it some more time today…

This line solves the issue:




data: "' . Yii::app()->request->csrfTokenName.'='.Yii::app()->request->getCsrfToken() . '" + (typeof($(this).attr("value")) == "undefined" ? "&cancel=1": "&rate=" + $(this).val())  + "&id=' . $data->id . '",



thanks ! :lol: