akhanisatyammg / jquery-star-rating-plugin

Automatically exported from code.google.com/p/jquery-star-rating-plugin
0 stars 0 forks source link

Registering a callback for rating submission does not work #58

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 

I know the error is on my side but I just can't figure out how to use the
jquery star rating code. I can get the stars to be displayed. But I just
can't get the callback ever invoked.

So any idea what is wrong with my code?

Thanks for any help!!
Fabian

What version of the plugin/jQuery are you using?
PLUGIN VERSION: v3.13
JQUERY VERSION: v1.4.2

On what browser(s) or operating system?
BROWSER(S): Linux Firefox and Chromium

My html code is this:

<html>
<head>
    <script type="text/javascript"
src='http://localhost:8000/media/js/jquery.js'></script>
    <script type="text/javascript" language="javascript"
src='http://localhost:8000/media/js/jquery.rating.js'></script>
    <link rel="stylesheet" type="text/css" media="all"
href="http://localhost:8000/media/css/jquery.rating.css" />         
</head>
<body>

<form id="rating_form">
    <script>
        $(document).ready(function(){
            $('.star').rating({
                callback: function(value, link){
                    alert("The value selected was '" + value + "'\n\nWith
this callback function I can automatically submit the form with this
code:\nthis.form.submit();");
                    // To submit the form via ajax:
                    //$(this.form).ajaxSubmit();
                }
            });
       });
    </script>

    <input name="star2" value="1" type="radio" class="star" />
    <input name="star2" value="2" type="radio" class="star" />
    <input name="star2" value="3" type="radio" class="star" />
    <input name="star2" value="4" type="radio" class="star" />
    <input name="star2" value="5" type="radio" class="star" />
    <input type="submit" value="Submit"/>
</form>
</body>
</html>

Original issue reported on code.google.com by fabio.st...@gmail.com on 17 May 2010 at 1:42

GoogleCodeExporter commented 8 years ago
I believe you must use something other than '.star' as your selector.

Original comment by craftbee...@gmail.com on 25 May 2010 at 9:39

GoogleCodeExporter commented 8 years ago
I just submitted a similar issue before noticing this one.  The problem is 
that, at the bottom of the plugin .js file, there is some lines that read:

        /*
        ### Default implementation ###
        The plugin will attach itself to file inputs
        with the class 'multi' when the page loads
    */
    $(function(){
     $('input[type=radio].star').rating();
    });

As a result, when you try to attach your callback event later, such as:

      $('input').rating({
        callback: function(){ alert(1); }
      });

The callback never gets attached because the control was already created by the 
"default implementation" at the bottom of the plugin .js file.

You can get around this bug by removing those lines from the plugin.js - just 
note that this means it will *not* automagically apply the star plugin stuff to 
your radio inputs.

Original comment by belor...@gmail.com on 24 Aug 2010 at 9:01

GoogleCodeExporter commented 8 years ago
thx. It's working now!

Original comment by Pascal.W...@gmail.com on 26 Mar 2012 at 10:19

GoogleCodeExporter commented 8 years ago

Original comment by diego.a...@gmail.com on 27 Mar 2012 at 9:20

GoogleCodeExporter commented 8 years ago
@ belor...@gmail.com, I've used your suggestions but now the problem is it 
doesnot show filled star image on the radio inputs that have checked attribute 
(as stated in the documentations it should display the prefilled star on the 
radio inputs with checked attribute). I dont understand is there any other way 
of using the callback function instead of the hack that you have provided...

Original comment by faraz1...@gmail.com on 21 Apr 2012 at 7:26

GoogleCodeExporter commented 8 years ago
Faraz, please provide a link to your implementation so we can take a look.

The problem is this:
By default, the plugin installs itself to any input with the class "star". But 
it does this without any options or callbacks.

In order to have your own callback you need to define this when you invoke the 
plugin, eg.:
http://jsfiddle.net/y9hrf/2/

Original comment by diego.a...@gmail.com on 23 Apr 2012 at 11:08

GoogleCodeExporter commented 8 years ago
This solution worked for me!!

Why put the auto initialize inside the plugin.js file

Original comment by ple...@gmail.com on 11 Nov 2012 at 4:51