aw schriftzug.png aw logo 60x60.png

RatingContrib

Rating widget for forms

This is a rating widget that can support a "line of stars" style input field.

Usage

You can use the new rating type in form fields. The result of the rating is captured as an integer, and displayed as a line of stars. For example,

example stars.gif

Install the contrib. You can immediately use the rating type in your forms. Rating values are stored as integers.

To use it in a form, use the type rating, with the optional modified +small for small stars. The size field dictates how wide the rating is e.g. 5 means a 5 star range. The value field specifies the initial value. For example, the form definition:

| *Name*     | *Type*       | *Size* | *Values* |
| Supplier   | text         | 40     |          |
| Quality    | rating+small | 10     | 5        |
| Order Date | date         |        |          |
looks like this when it is edited:

edit example.gif

Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.

Using the Contrib in a Plugin

A typical application of this widget is its use to capture a rating under the control of a plugin. It is straightforward to use in this role. The API to the contrib is:

Foswiki::Contrib::RatingContrib::renderRating($name, $size, $small, $value, $input_attrs) → $html

where
  • $name is the name you want to give to the input element that will get the rating value
  • $size is the total width of the rating bar, typically 5 or 10
  • $small is a boolean; if true, use small (10px) stars in place of the default (25px) stars
  • $value is the current value of the rating. This may be a floating-point value, but should be in the range 0..$size
  • $input_attrs is a hash that contains additional attributes to be assigned to the input element used to capture the rating value. Typically the only attribute callers will need to use is onchange, which should be set to a callback that will be invoked when the value in the input is changed. If you pass undef for this parameter, then the line of stars will be "read only".
The contrib will automatically look after the CSS and Javascript it needs to load to work.

For example, let's say we want to generate a conventional form that contains a line of stars prompt. We want the value of the rating bar to be submitted along with everything else in the form.
my $html =
   CGI::form({action="some url", method=>"post"},
       Foswiki::Contrib::RatingContrib::renderRating('rating', 5, 0, 0, {})
      .CGI::submit("OK"));

Say instead that we want to generate an alert when a line of stars has its value changed:
$html = Foswiki::Contrib::RatingContrib::renderRating('rating', 5, 0, 0,
        {onchange=>'javascript: alert("Rated")'})
Of course, when you use the onchange event, you don't need a form. This model is good if you want (for example) to update values using a REST handler.

Contrib Info

Author(s): Crawford Currie http://c-dot.co.uk
Copyright: © 2007 C-Dot Consultants
License: GPL (Gnu General Public License)
Version: 4083 (2009-06-10)
Change History:  
10 Jun 2009: Foswikitask:1258: port to Foswiki
27 Jun 2006: First version
Dependencies: None
Home: http://foswiki.org/Extensions/RatingContrib
Support: http://foswiki.org/Support/RatingContrib

Related Topics: Contribs, DeveloperDocumentationCategory, AdminDocumentationCategory, DefaultPreferences, SitePreferences

Topic attachments
I Attachment Action Size Date Who Comment
edit_example.gifgif edit_example.gif manage 7 K 2009-06-10 - 19:52 AlexanderWeimer  
example_stars.gifgif example_stars.gif manage 1 K 2009-06-10 - 19:52 AlexanderWeimer  
ie_pick_star.gifgif ie_pick_star.gif manage 409 bytes 2009-06-10 - 19:52 AlexanderWeimer  
ie_pick_star_small.gifgif ie_pick_star_small.gif manage 185 bytes 2009-06-10 - 19:52 AlexanderWeimer  
ie_star.gifgif ie_star.gif manage 1 K 2009-06-10 - 19:52 AlexanderWeimer  
ie_star_small.gifgif ie_star_small.gif manage 396 bytes 2009-06-10 - 19:52 AlexanderWeimer  
leftbar.gifgif leftbar.gif manage 196 bytes 2009-06-10 - 19:52 AlexanderWeimer  
mainbar.gifgif mainbar.gif manage 148 bytes 2009-06-10 - 19:52 AlexanderWeimer  
pick_star.gifgif pick_star.gif manage 513 bytes 2009-06-10 - 19:52 AlexanderWeimer  
pick_star_small.gifgif pick_star_small.gif manage 284 bytes 2009-06-10 - 19:52 AlexanderWeimer  
rating.csscss rating.css manage 1 K 2009-06-10 - 19:52 AlexanderWeimer  
rating.jsjs rating.js manage 323 bytes 2009-06-10 - 19:52 AlexanderWeimer  
rightbar.gifgif rightbar.gif manage 196 bytes 2009-06-10 - 19:52 AlexanderWeimer  
star.gifgif star.gif manage 2 K 2009-06-10 - 19:52 AlexanderWeimer  
star_small.gifgif star_small.gif manage 565 bytes 2009-06-10 - 19:52 AlexanderWeimer  
stars.svgsvg stars.svg manage 12 K 2009-06-10 - 19:52 AlexanderWeimer  
Topic revision: r6 - 2017-02-17, UnknownUser
This site is powered by FoswikiCopyright &© by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback