Backing field mulitplier

Nov 22, 2013 at 9:14 AM
Hello,

We love this plugin but we have to modify it so we can have a multiplier on the backing field.

eg: This allows us to for example to show a rating of 1.5 but submit a value of 15.

$(function () { $("#bitter").rateit({backingfld: "#ratingfield", max: 5, multiplier: 10, step: 0.5, value: 1.5 }); });

It would be gread if this could be added as an additional option.

Here is an eclipse patch for what we are using. I can post the complete source if needed.

Cheers Greg.

Eclipse Workspace Patch 1.0

P Events

Index: src/main/webapp/events-ui/scripts/rateit-1.0.15/src/jquery.rateit.js

--- src/main/webapp/events-ui/scripts/rateit-1.0.15/src/jquery.rateit.js (revision 1883)
+++ src/main/webapp/events-ui/scripts/rateit-1.0.15/src/jquery.rateit.js (working copy)
@@ -1,5 +1,6 @@
/*! RateIt | v1.0.15 / 11/13/2013 | https://rateit.codeplex.com/license
 http://rateit.codeplex.com | Twitter: @gjunge
  • GA Added multiplier
    */
    (function ($) {
    $.rateit = {
    @@ -108,6 +109,7 @@
             itemdata('min', itemdata('min') || options.min);
             itemdata('max', itemdata('max') || options.max);
             itemdata('step', itemdata('step') || options.step);
  • itemdata('multiplier', itemdata('multiplier') || options.multiplier); // +
             itemdata('readonly', itemdata('readonly') !== undefined ? itemdata('readonly') : options.readonly);
             itemdata('resetable', itemdata('resetable') !== undefined ? itemdata('resetable') : options.resetable);
             itemdata('backingfld', itemdata('backingfld') || options.backingfld);
    @@ -121,7 +123,7 @@
             if (itemdata('backingfld')) {
                 //if we have a backing field, hide it, and get its value, and override defaults if range.
                 var fld = $(itemdata('backingfld'));
  • itemdata('value', fld.hide().val());
  • itemdata('value', fld.hide().val() / itemdata('multiplier')); //
                 if (fld.attr('disabled') || fld.attr('readonly')) 
                     itemdata('readonly', true); //http://rateit.codeplex.com/discussions/362055 , if a backing field is disabled or readonly at instantiation, make rateit readonly.
    @@ -133,6 +135,7 @@
                         itemdata('min', parseInt(fld.attr('min')) || itemdata('min')); //if we would have done fld[0].min it wouldn't have worked in browsers not supporting the range type.
                         itemdata('max', parseInt(fld.attr('max')) || itemdata('max'));
                         itemdata('step', parseInt(fld.attr('step')) || itemdata('step'));
  • itemdata('multiplier', parseInt(fld.attr('multiplier')) || itemdata('multiplier')); // +
                     }
                 }
                 if (fld[0].nodeName == 'SELECT' && fld[0].options.length > 1) {
    @@ -139,6 +142,7 @@
                     itemdata('min', Number(fld[0].options[0].value));
                     itemdata('max', Number(fld[0].options[fld[0].length - 1].value));
                     itemdata('step', Number(fld[0].options[1].value) - Number(fld[0].options[0].value));
  • itemdata('multiplier', Number(fld[0].options[1].value)); // +
                 }
             }
    
@@ -217,7 +221,7 @@
         var setSelection = function (value) {
             itemdata('value', value);
             if (itemdata('backingfld')) {
  • $(itemdata('backingfld')).val(value);
  • $(itemdata('backingfld')).val(value * itemdata('multiplier')); //
             }
             if (itemdata('ispreset')) { //if it was a preset value, unset that.
                 range.find('.rateit-selected').removeClass(presetclass);
    @@ -302,7 +306,7 @@
    };

    //some default values.
  • $.fn.rateit.defaults = { min: 0, max: 5, step: 0.5, starwidth: 16, starheight: 16, readonly: false, resetable: true, ispreset: false};
  • $.fn.rateit.defaults = { min: 0, max: 5, step: 0.5, multiplier: 1.0, starwidth: 16, starheight: 16, readonly: false, resetable: true, ispreset: false}; //

    //invoke it on all .rateit elements. This could be removed if not wanted.
    $(function () { $('div.rateit, span.rateit').rateit(); });
Nov 24, 2013 at 7:22 AM
Hi Greg,

I understand your requirement (actually I have the same requirement on my website).
At the moment I'm a bit hesitant of adding it to RateIt:
  • I do not want a feature overkill.
  • I try to keep on par with the default controls (for example the normal range control, doesn't contain a feature like this)
  • I think that this is the job of the server side code. The server should transform any value so that the UI can use it. Much like a server would save a date in its own value, yet output it as ISO format so that the date control can use it.
regards,
Gidon