Not an issue, but I though someone may find this useful.

We wanted to display % values (Start:0, Step:1, Max 100) entered into a slider field in a progress bar, and found that it was very simple. Note: for this example to work, you must add '%' as a suffix, although this isn't cruical, as you could add an echo into **** and % into the span width.

After configuring our field (we'll call it 'Progress', with the machine name 'field_progress'), we just need to create a field--field_progress.tpl.php, and replacing the default field.tpl.php's code with the following:

<div class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <?php if (!$label_hidden): ?>
    <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
  <?php endif; ?>
  <div class="field-items"<?php print $content_attributes; ?>>
    <?php foreach ($items as $delta => $item): ?>
    <div class="meter" title="<?php print render($item); ?>">
      <span id="meter-value-<?php print $element['#object']->nid; ?>" style="width: <?php print render($item); ?>;"></span>
    <?php endforeach; ?>
  </div>
</div>

Then, we just need to add the CSS3. I've used the class 'meter' for simplicity, as it's used in CSS-Tricks' great tutorial: CSS3 Progress Bars.

By just adding the following to your style, you'll replicate their example:

.meter { 
	height: 20px;  /* Can be anything */
	position: relative;
	background: #555;
	-moz-border-radius: 25px;
	-webkit-border-radius: 25px;
	border-radius: 25px;
	padding: 10px;
	-webkit-box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
	-moz-box-shadow   : inset 0 -1px 1px rgba(255,255,255,0.3);
	box-shadow        : inset 0 -1px 1px rgba(255,255,255,0.3);
}

.meter > span {
	display: block;
	height: 100%;
	   -webkit-border-top-right-radius: 8px;
	-webkit-border-bottom-right-radius: 8px;
	       -moz-border-radius-topright: 8px;
	    -moz-border-radius-bottomright: 8px;
	           border-top-right-radius: 8px;
	        border-bottom-right-radius: 8px;
	    -webkit-border-top-left-radius: 20px;
	 -webkit-border-bottom-left-radius: 20px;
	        -moz-border-radius-topleft: 20px;
	     -moz-border-radius-bottomleft: 20px;
	            border-top-left-radius: 20px;
	         border-bottom-left-radius: 20px;
	background-color: rgb(43,194,83);
	background-image: -webkit-gradient(
	  linear,
	  left bottom,
	  left top,
	  color-stop(0, rgb(43,194,83)),
	  color-stop(1, rgb(84,240,84))
	 );
	background-image: -webkit-linear-gradient(
	  center bottom,
	  rgb(43,194,83) 37%,
	  rgb(84,240,84) 69%
	 );
	background-image: -moz-linear-gradient(
	  center bottom,
	  rgb(43,194,83) 37%,
	  rgb(84,240,84) 69%
	 );
	background-image: -ms-linear-gradient(
	  center bottom,
	  rgb(43,194,83) 37%,
	  rgb(84,240,84) 69%
	 );
	background-image: -o-linear-gradient(
	  center bottom,
	  rgb(43,194,83) 37%,
	  rgb(84,240,84) 69%
	 );
	-webkit-box-shadow: 
	  inset 0 2px 9px  rgba(255,255,255,0.3),
	  inset 0 -2px 6px rgba(0,0,0,0.4);
	-moz-box-shadow: 
	  inset 0 2px 9px  rgba(255,255,255,0.3),
	  inset 0 -2px 6px rgba(0,0,0,0.4);
	position: relative;
	overflow: hidden;
}

Flush the cache and it should be working perfectly.

A few points...

  • We added the 'id="meter-value-nid"' to the span, as we wanted to have control over indivdual bars, but it's optional.
  • We added the 'title=""' to the
    , as it gives the percentage on hover, and in our case, we've targeted '.meter' with BeautyTips, and we've got a tooltip with the % on hover. This is again optional.

Comments

rdeboer’s picture

Nice one!
Thanks for sharing.

sinasalek’s picture

Version: 7.x-1.0-beta1 » 7.x-2.0-alpha2

I'll see what i can do to include part of this in a generic way into version 2
Feed free to write a patch if you had time. Note that slider value prefix and suffix is supported for FAPI already but not yet accessible through UI #2004384: Example for using display_values_format. Also There is another feature request regarding progress hints #1409636: Add a "ballon" popup option.

sinasalek’s picture

Version: 7.x-2.0-alpha2 » 7.x-2.x-dev
sinasalek’s picture

Status: Active » Closed (fixed)