Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting value does not display correct rating (i.e. number of stars) #16

Open
wloescher opened this issue Jan 31, 2014 · 4 comments
Open

Comments

@wloescher
Copy link

I'm using your fine little piece of code in a Bootstrap 3 modal pop up. I'm setting the value of the control, and it appears to get set correctly.
$("#rating").val(3);
alert($("#rating").val()); // 3

However, no stars are selected when the controls is rendered.

Tested in Chrome, FF, and IE.

@javiertoledo
Copy link
Owner

The plugin was not designed to act via JS as a conventional input, but it would definitively be a very nice addition! I'll address this on some near future as soon as I find some spare time, thanks for your feedback!

Meanwhile you should be able to activate the stars and assign the value with a function similar to this one (I haven't tested it):

function assign_val(ratingInputSelector, value) {
  var selectedStar = $(ratingInputSelector).find('[data-value=' + value + ']');
  selectedStar.removeClass('glyphicon-star-empty').addClass('glyphicon-star');
  selectedStar.prevAll('[data-value]').removeClass('glyphicon-star-empty').addClass('glyphicon-star');
  selectedStar.nextAll('[data-value]').removeClass('glyphicon-star').addClass('glyphicon-star-empty');
  selectedStar.siblings('input').val(value).trigger('change');
}

@wloescher
Copy link
Author

Works like a charm...cheers!

@wloescher
Copy link
Author

I spoke slightly too soon...I needed to edit just the first line of the function to go up to parent (div.rating-input) of my ratingInputSelector to get it to work correctly.
var selectedStar = $(ratingInputSelector).parent().find("[data-value=" + value + "]");

@findchris
Copy link

Thank you both. This worked just as I wanted it to, allowing the same input to be used for both new and existing records.
👍 on merging this functionality!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants