Yii Framework Forum: CStarRating remove vote - Yii Framework Forum

Jump to content

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

CStarRating remove vote Rate Topic: -----

#1 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 17 October 2011 - 04:49 PM

If you push on it , it writes

e.nodeName is undefined
[Break On This Error] (function(a,B){function cy(a){return f...h]&&f.event.trigger(c,d,b.handle.elem 


example here http://www.yiiplaygr...ther/starRating
+ open firebug to see

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

#2 User is offline   Maurizio Domba Cerin 

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

Posted 19 October 2011 - 03:41 AM

This has already being asked here - http://www.yiiframew...oblem-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
Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 19 October 2011 - 08:54 AM

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


this is yii playground issue http://code.google.c...ues/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...
0

#4 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 19 October 2011 - 05:43 PM

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 . '",

1

#5 User is offline   yiqing95 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 602
  • Joined: 27-December 10
  • Location:china

Posted 03 December 2012 - 12:35 AM

View Postdckurushin, on 19 October 2011 - 05:43 PM, said:

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:
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