bootstrap-rating-input
bootstrap-rating-input copied to clipboard
Setting value does not display correct rating (i.e. number of stars)
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.
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');
}
Works like a charm...cheers!
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 + "]");
Thank you both. This worked just as I wanted it to, allowing the same input to be used for both new and existing records.
:+1: on merging this functionality!