2 of 2
2
Can you use a <ul> instead of <select> for rating in the form? 
Posted: 01 April 2008 08:53 AM   [ Ignore ]   [ # 16 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Well, way to go Pie Man! Leave me hangin’ for 10 days. wink (j/k)

Didn’t know Chris was the code master behind this. He’s helped me out a time or two with other EE stuff. Very nice guy.

Profile
 
 
Posted: 01 April 2008 10:05 AM   [ Ignore ]   [ # 17 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

You mentioned you already know how to style a UL. Can you show me the code you use for it? Maybe I can convert it so that it works with SELECT.

 Signature 
Profile
 
 
Posted: 01 April 2008 10:44 AM   [ Ignore ]   [ # 18 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Hey Chris,

Thanks for stopping by!

The rating script I used on one of my sites: http://www.nicestylesheet.com is http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/. While the script dynamically generates the UL in the HTML, I just copied and pasted the below from the HTML source and the CSS from my CSS file. I’m using the exact same stars for the rating on NiceStylesheet as I will be using on my other site. You can view what I’ve got thus far here: http://www.kentuckygolfing.com/courses/details/valhalla-golf-club. As you can see, it will work as is, but I just want to replace the select field in the rating form with the star rollovers.

Here’s the CSS:

#content .ratingblock {
display: block;
font-size: 85%;
}

#content .ratingblock .loading {
height: 16px;
background: url('/images/working.gif') 50% 50% no-repeat;
}

#content .ratingblock .unit-rating { /* the UL */
list-style:  none;
height: 16px;
position: relative;
background: url('/images/starrating.gif') top left repeat-x;  
}

#content .ratingblock .unit-rating li{
text-indent: -90000px;
padding: 0px;
margin: 0px;
/*\*/
float: left;
/* */
}

#content .ratingblock .unit-rating li a {
outline: none;
display: block;
width: 16px;
height: 16px;
text-decoration: none;
text-indent: -9000px;
z-index: 20;
position: absolute;
padding: 0px;
}

#content .ratingblock .unit-rating li a:hover{
background: url('/images/starrating.gif') left center;
z-index: 2;
left: 0px;
}

#content .ratingblock .unit-rating a.r1-unit {left: 0px;}
#content .ratingblock .unit-rating a.r1-unit:hover {width:16px;}
#content .ratingblock .unit-rating a.r2-unit {left:16px;}
#content .ratingblock .unit-rating a.r2-unit:hover {width: 32px;}
#content .ratingblock .unit-rating a.r3-unit {left: 32px;}
#content .ratingblock .unit-rating a.r3-unit:hover {width: 48px;}
#content .ratingblock .unit-rating a.r4-unit {left: 48px;}
#content .ratingblock .unit-rating a.r4-unit:hover {width: 64px;}
#content .ratingblock .unit-rating a.r5-unit {left: 64px;}
#content .ratingblock .unit-rating a.r5-unit:hover  {width: 80px;}

#content .ratingblock .unit-rating li.current-rating {
background: url('/images/starrating.gif') left bottom;
position: absolute;
height: 16px;
display: block;
text-indent: -9000px;
z-index: 1;
}

and the HTML:

<div class="ratingblock">
<
div id="unit_long237">  
  <
ul id="unit_ul237" class="unit-rating" style="width:80px;">  
   <
li class="current-rating" style="width:36px;">Currently 2.25/5</li>  
  </
ul>  
</
div>
</
div>

I actually found this the other day: http://www.unessa.net/en/hoyci/projects/yui-star-rating/#3. He used a select field in the demo, but I can’t seem to get it to work and as Mitchell said, it seemed more difficult.


EDIT: After I look at the HTML above, I see that it’s only the HTML for the “current rating.” Like I said, I had to pull it from the HTML source since the HTML is dynamically generated and all I have in my HTML is a php echo statement and since all the designs on my site have already been rated, this is what I’ve got. Let me know if that doesn’t work for what you need

Profile
 
 
Posted: 01 April 2008 12:13 PM   [ Ignore ]   [ # 19 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

The YUI code is complete overkill for what you need. You showed an example site of what you’re wanting to do in your first post. I took that code and wrote a little JS for it that will let you use their code, and still work with the Ratings module. You’ll need to have jQuery for this to work too.

First, you’ll need to have the following code in your HEAD tag:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
  
$('a').focus(function(event) {
   
$(this).blur();
  
});
  
  $(
'ul.rating li a').click(function(event) {
   event
.preventDefault();
   var
par  = $(this).parents('ul.rating');
   var
id   = $(par).attr('id');
   var
num  = $(this).text();
   $(
par).removeClass().addClass('rating star'+num);
   $(
'#rating-'+id).val(num);
  
});
});
// ]]>
</script>

Then you’ll need to make a couple alterations to their HTML code:

<input name="rating" id="rating-{entry_id}" type="text" value="" /><br />
<
ul id="{entry_id}" class="rating star{rating}">
<
li class="one"><a href="#" title="1 Star">1</a></li>
<
li class="two"><a href="#" title="2 Stars">2</a></li>
<
li class="three"><a href="#" title="3 Stars">3</a></li>
<
li class="four"><a href="#" title="4 Stars">4</a></li>
<
li class="five"><a href="#" title="5 Stars">5</a></li>
</
ul>

And you’ll also need to change some of their CSS code:

.star0 {background-position:0 0}
.star1 {background-position:0 -16px}
.star2 {background-position:0 -32px}
.star3 {background-position:0 -48px}
.star4 {background-position:0 -64px}
.star5 {background-position:0 -80px}

Once you’ve got it working, then just change:

<input name="rating" id="rating-{entry_id}" type="text" value="" />

to

<input name="rating" id="rating-{entry_id}" type="hidden" value="" />

I hope this makes sense. Reading over it, I’m not sure if it does. Let me know if you have questions.

 Signature 
Profile
 
 
Posted: 01 April 2008 08:19 PM   [ Ignore ]   [ # 20 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Chris,

Thanks for taking the time to put this together!

It does make sense to me what’s going on in the whole process, but the javascript doesn’t really mean anything to me (I just don’t know javascript… I need to learn). With that said, visually, the stars work. The roll over and click functionality of the stars is fine, but I’m getting this message at the top of my page:

Notice: Undefined variable: rating in /www/eh6420/public_html/kygolfing/q2w3e41/modules/rating/mod.rating.php on line 1231

I’m not quite sure why? I’ve followed your instructions from the last post as close as I can and have double checked a couple times now (may still be missing something?). Here is the template where I’m trying to do this: http://www.kentuckygolfing.com/courses/details/valhalla-golf-club

The review I left titled “test for stars” doesn’t seem to have recorded a rating (even though I had selected 4 stars)

Thanks

Profile
 
 
Posted: 02 April 2008 04:45 PM   [ Ignore ]   [ # 21 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

Looking at your rendered template, I can see that {entry_id} isn’t getting parsed. Try fixing that and see if it helps.

 Signature 
Profile
 
 
Posted: 02 April 2008 05:05 PM   [ Ignore ]   [ # 22 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19
Chris Ruzin - 02 April 2008 04:45 PM

Looking at your rendered template, I can see that {entry_id} isn’t getting parsed. Try fixing that and see if it helps.

Hey Chris, I guess that’s my problem. I’m not quite sure what needs fixing so that it will be parsed?

Here is my template code:

{exp:rating:form  form_id="rating" entry_id="{entry_id}" form_name="review" require_membership="no" admin_template="admin_template" status="open"}
  
<fieldset>
  <
div class="formField">
  <
label for="name" class="labelName"><span class="requiredAst">*</span> Name:</label><br />
  <
input type="text" name="name" size="40" id="name" class="inputField" />
  </
div>

  <
div class="formField">   
  <
label for="email" class="labelName"><span class="requiredAst">*</span> Email Address:</label><br />
  <
input type="text" name="email" size="40" id="email" class="inputField" />
  </
div>
  
  <
div class="formField">
  <
label for="review"><span class="requiredAst">*</span> Name:</label> Your Rating:</label><br />
  <
input name="rating" id="rating-{entry_id}" type="text" value="" /><br />
  <
ul id="{entry_id}" class="rating star{rating}">
    <
li class="one"><a href="#" title="1 Star">1</a></li>
    <
li class="two"><a href="#" title="2 Stars">2</a></li>
    <
li class="three"><a href="#" title="3 Stars">3</a></li>
    <
li class="four"><a href="#" title="4 Stars">4</a></li>
    <
li class="five"><a href="#" title="5 Stars">5</a></li>
  </
ul>
  </
div>

  <
div class="formField">   
  <
label for="title" class="labelName"><span class="requiredAst">*</span> Review Title:</label><br />
  <
input type="text" name="review_title" size="40" id="title" class="inputField" />
  </
div>

  <
div class="formField">
  <
label for="review"><span class="requiredAst">*</span> Your Review:</label><br />
  <
textarea name="review" rows='' cols=''></textarea>
  </
div>
  
  <
p class="indicatesRequired"><span class="requiredAst">*</span> Indicates required fields</p>

  <
div class="formField">
  <
input type="submit" class="submit" name="submit" value="Submit" />
  </
div>
  </
fieldset>
  
{/exp:rating:form}

It seems at though the entry_id is being parsed just fine in the opening {exp:rating:form} tag as this is what I see when I view the source:

<form id='rating' name='review' method="post" action="http://www.kentuckygolfing.com/courses/details/valhalla-golf-club/"  >
<
div class='hiddenFields'>
<
input type="hidden" name="ACT" value="76" />
<
input type="hidden" name="RET" value="http://www.kentuckygolfing.com/courses/details/valhalla-golf-club/" />
<
input type="hidden" name="URI" value="/courses/details/valhalla-golf-club/" />
<
input type="hidden" name="PRV" value="" />

<
input type="hidden" name="XID" value="0eee5acd0c9f906b85bc1ff74211bccb9db976fc" />
<
input type="hidden" name="entry_id" value="327" />
<
input type="hidden" name="form_name" value="review" />
<
input type="hidden" name="status" value="open" />
<
input type="hidden" name="anonymous" value="n" />
<
input type="hidden" name="allow_duplicates" value="y" />
<
input type="hidden" name="user_template" value="" />
<
input type="hidden" name="admin_template" value="admin_template" />
<
input type="hidden" name="required" value="" />
<
input type="hidden" name="site_id" value="1" />
</
div>


  <
fieldset>
  <
div class="formField">

  <
label for="name" class="labelName"><span class="requiredAst">*</span> Name:</label><br />
  <
input type="text" name="name" size="40" id="name" class="inputField" />
  </
div>

  <
div class="formField">   
  <
label for="email" class="labelName"><span class="requiredAst">*</span> Email Address:</label><br />
  <
input type="text" name="email" size="40" id="email" class="inputField" />

  </
div>
  
  <
div class="formField">
  <
label for="review"><span class="requiredAst">*</span> Name:</label> Your Rating:</label><br />
  <
input name="rating" id="rating-{entry_id}" type="text" value="" /><br />
  <
ul id="{entry_id}" class="rating star">
    <
li class="one"><a href="#" title="1 Star">1</a></li>

    <
li class="two"><a href="#" title="2 Stars">2</a></li>
    <
li class="three"><a href="#" title="3 Stars">3</a></li>
    <
li class="four"><a href="#" title="4 Stars">4</a></li>
    <
li class="five"><a href="#" title="5 Stars">5</a></li>
  </
ul>
  </
div>

In the hidden input fields above, it shows the correct entry_id, so I’m not sure where to start here…

Profile
 
 
Posted: 02 April 2008 05:59 PM   [ Ignore ]   [ # 23 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

Is it possible for me to get EE access to this site?

 Signature 
Profile
 
 
Posted: 02 April 2008 06:06 PM   [ Ignore ]   [ # 24 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Sure, PM sent.

Profile
 
 
Posted: 02 April 2008 09:16 PM   [ Ignore ]   [ # 25 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

You’re good to go. I added an weblog:entries tag around the rating:form tag. I also fixed the rating label and made the ratings field hidden. I tested it twice and it worked both times.

 Signature 
Profile
 
 
Posted: 03 April 2008 08:12 AM   [ Ignore ]   [ # 26 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Ah that awesome Chris! I can’t thank you enough for this! Solspace should just integrate this into the module by default. wink

I hear you’re the resident jQuery master (obviously). What do you recommend for someone clueless like myself trying to learn a little? Just tutorials on jQuery’s website? Books?

Profile
 
 
Posted: 03 April 2008 08:58 AM   [ Ignore ]   [ # 27 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

Glad you’re happy with it. Regarding learning jQuery, look at examples in both the jQuery docs and on people’s sites. It’s pretty straightforward really. I know it makes JS coding fun again.

Oh, there’s also a book I got which was quite helpful called Learning jQuery by Packt Publishing.

 Signature 
Profile
 
 
Posted: 03 April 2008 11:51 AM   [ Ignore ]   [ # 28 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Yeah, I keep reading that jQuery really isn’t that hard and most of the time, when someone gives me some code, I can look at it and kinda tell what’s going on, but I couldn’t have written it myself. I guess it’s like anything else. I remember first starting with CSS and thinking that it must be the most difficult thing in the world to learn. After three years of doing it, I don’t even think anything about it now.

Yeah, I’ve seen that book advertised on the jQuery website and thought about picking it up. I just wasn’t sure if it was geared more toward beginners (we’re talking zero experience) or if it assumed you had some knowledge already. I might grab it though or at least run up to barnes and noble and do some reading to see if it’s something I think I could learn.

Do you hang around the forums here much? I might have another jQuery question at some point soon. I posted here: http://www.solspace.com/forums/viewthread/769/ and I’ve not had a chance to try it yet, but I’m going to give what Mitchell gave me a shot. I just have a feeling it will end up working out like everything else I’ve tried with jQuery… not good. wink I don’t want to bombard you with questions though. I don’t mind a bit to pay you for your help.

Profile
 
 
Posted: 03 April 2008 12:23 PM   [ Ignore ]   [ # 29 ]
Administrator
Avatar
Rank
Total Posts:  17
Joined  2005-03-22

Not sure why you’re having a hard time with jQuery solutions. It’s an amazing library that has made our job of coding front-end wizardry sooooo much easier. EE 2.0 will be using it by default. I guess it does help if you know JS to begin with though.

 Signature 
Profile