question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set InitialRating for multiple select

See original GitHub issue

I have multiple select box which comes from database. I added “data-current-rating” to select option. But, can’t set initial rating using this option.


<select class="stars" data-current-rating="3.5">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
<option value="4"></option>
<option value="5"></option>
</select>

<select class="stars" data-current-rating="4.4">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
<option value="4"></option>
<option value="5"></option>
</select>
$('.stars').barrating('show', {
        theme: 'fontawesome-stars-o',
        emptyValue: 0,
        readonly: true,
        initialRating: $(this).data('current-rating')
    });

Of course, I can set initialRating value from option selected, but due to case, I will not able to display fractional star.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
ChetanGoticommented, Nov 22, 2017

Try this. (as I mentioned at https://github.com/antennaio/jquery-bar-rating/issues/99#issuecomment-346353975)

$('.stars').each(function(index, el) {
  var $El = $(el);
  $El.barrating({
    theme: 'fontawesome-stars-o',
    initialRating: $El.attr('data-current-rating') 
  });
});
1reaction
timgavincommented, Oct 18, 2017

@mdefrancq Try this; works for me.

<select id="ratings" name="rating" data-current-rating="2">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
</select>

<script>
    $(function() {
        $('#ratings').barrating({
            theme: 'fontawesome-stars',
            initialRating: $('#ratings').data('current-rating'),
        });
    });
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

bar rating - wanting default selection to be no selection
In this jquery bar rating library, we can set no value selected by default on bar. <script> $('#rating').barrating('show', ...
Read more >
What is the best way to set two rating value in a web based ...
I'm working on a web based application, so it will be used on desktop and mobile devices. The problem is, that I'm looking...
Read more >
Select Multiple select Example - Mobiscroll
Select - Setting values​​ Values can change in a couple different ways: though defaults, interacting with the UI or programmatically. The select ......
Read more >
Select ranges in Final Cut Pro - Apple Support
In the timeline, you can also select a range that spans multiple clips. You can trim range selections, mark them with ratings and...
Read more >
Create Multi select Checkboxes in Power Apps for SharePoint ...
Video covers the following: ✓ How to create Multi Select Checkboxes in ... in Power Apps using Radio control 08:33 - Set Required...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found