auxiliary/rater

Initial value incorrect when 'update_input_field_name' is setted

debaser opened this issue · 4 comments

The bond field always gets initial value 5.

This wrong value is set in line 173:
this.value = this.toValue(selected_width * $(base_layer).textWidth());

@debaser The update_input_field_name is used to set a text field that gets updated with the value of the rate once it's changed. If you want to set an initial value for the rater, you have to use the initial_value option. Also, line 173 uses selected_width and that's calculated based on the initial value at line 121. Please let me know if I misunderstood and there's actually a bug there.

Hi!,

Please, test this simple code, and notice that the input value will change
to 5. Thank you

<title>Rater</title> <script src=' http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src=' https://raw.githubusercontent.com/auxiliary/rater/master/rater.js'></script>

<script> $(document).ready(function() { $("#rating").rate({ symbols: { custom: { base: '\u2605', hover: '\u2605', selected: '\u2605', }, }, selected_symbol_type: 'custom', max_value: 5, step_size: 1, initial_value: $("#rate").val() || 0, cursor: 'pointer', update_input_field_name: $("#rate") }); }); </script>

El mar., 9 feb. 2016 a las 0:51, Mohammad A.Raji (notifications@github.com)
escribió:

@debaser https://github.com/debaser The update_input_field_name is used
to set a text field that gets updated with the value of the rate once it's
changed. If you want to set an initial value for the rater, you have to use
the initial_value option. Also, line 173 uses selected_width and that's
calculated based on the initial value at line 121. Please let me know if I
misunderstood and there's actually a bug there.


Reply to this email directly or view it on GitHub
#4 (comment).

Here is a simplier code, better to understand, with the main info isolated:

<input type="text" id="rate" value="2" /> <!-- After the script, this value will change to 5 -->
<p id="rating"></p>

<script>
$(document).ready(function() {
  $("#rating").rate({
    max_value: 5,
    step_size: 1,
    initial_value: 2,
    cursor: 'pointer',
    update_input_field_name: $("#rate")
  });
});
</script>

hmm, I see. it should be fixed now. I'll close this issue. If the problem persists please reopen it.
BTW, in your sample code, you might want to change the base character to base: '\u2606' to be an empty star.