Hi,
The slider ranges from -2 to 2 in increments of 0.4.
In the code below, the html input "slider_one" is the slider seen be the subject, and the hidden input "check_slider_input" checks that the slider has been clicked.
The slider is giving dynamic feedback correctly on the current position of the slider. However, upon clicking the "Next" button to submit the form, I get the error "this field is required". I have not be able to figure why the values of the inputs "slider_one" and "check_slider_input" are not being recorded.Â
Thank you for any help on this.
html code:
...
  <input type="hidden" name="check_slider_one" value="" id="id_check_slider_one"/>
  <input type="range" name="slider_one" value="None" style="width: 380px" min="-2" max="2" step="0.4" id="id_slider_one" class="form-control"/>
  <div class="ticks" style="width: 380px">
    <span class="tick">-2</span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick">0</span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick"></span>
    <span class="tick">2</span>
  </div>
  <div style="width: 380px">
    <p style="text-align: center; margin-bottom: 0px" id="feedback_one"></p>
    <p style="text-align: center" id="feedback_two"></p>
  </div>
  <p style="padding-bottom: 10px"></p>
  {{ formfield_errors 'slider_one' }}
  {{ formfield_errors 'check_slider_one' }}
...
{{ block scripts }}
  <script>
    $(document).ready(function () {
      $('input[name=slider_one]').on('input change', function () {
        $('input[name=slider_one]').addClass('myClass');
      });
      $('input[name=slider_one]').on('input', function () {
        $('#check_slider_one').val(1);
        var sliderval = document.getElementById("id_slider_one").value;
        var payval = Math.abs(sliderval)/2;
        if (sliderval > 0) {
          document.getElementById("feedback_one").innerHTML = "Increase by: $"+$(this).val();
          document.getElementById("feedback_two").innerHTML = `You pay: $`+payval;
        } else if (sliderval == 0) {
          document.getElementById("feedback_one").innerHTML = "No change ($0)";
          document.getElementById("feedback_two").innerHTML = `You pay: $`+payval;
        } else if (sliderval < 0) {
          document.getElementById("feedback_one").innerHTML = "Decrease by: $"+Math.abs($(this).val());
          document.getElementById("feedback_two").innerHTML = `You pay: $`+payval;
        }
      });
      $('.otree-btn-next').click(function () {
        $('#id_slider_one').val(document.getElementById("id_slider_one").value);
        $('#id_check_slider_one').val(document.getElementById("id_check_slider_one").value);
      });
    });
  </script>
{{ endblock }}