bootstrap-rating-input icon indicating copy to clipboard operation
bootstrap-rating-input copied to clipboard

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

Open wloescher opened this issue 11 years ago • 4 comments

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.

wloescher avatar Jan 31 '14 23:01 wloescher

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');
}

javiertoledo avatar Feb 02 '14 21:02 javiertoledo

Works like a charm...cheers!

wloescher avatar Feb 03 '14 14:02 wloescher

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 + "]");

wloescher avatar Feb 03 '14 15:02 wloescher

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!

findchris avatar Feb 06 '14 15:02 findchris