I've used a code from this answer to style HTML5 input in my GRAV CMS website.
The rendered part of HTML markup:
<div class="form-data" data-grav-field="range" data-grav-disabled="" data-grav-default="40">
<div class="form-input-wrapper ">
<input name="data[space]" value="40" type="range" style="display: inline-block;vertical-align: middle;" oninput="space_output.value = space.value" min="40" max="350" step="10" class="form-input " id="space" required="required">
<output name="data[space]" id="space_output" style="display: inline-block;vertical-align: baseline;padding: 0 0.5em 5px 0.5em;"> 40 </output>
</div>
</div>
The JS code is taken from the answer above and placed in at the beginning of my custom.js
file:
document.getElementById("space").oninput = function() {
var value = (this.value-this.min)/(this.max-this.min)*100
this.style.background = 'linear-gradient(to right, #eec170 0%, #eea624 ' + value + '%, #839788 ' + value + '%, #a6d86c 100%)'
};
So, this part works without any flaws.
The problem:
With JS code the behaviour of input is incorrect, once the page is loaded background color is not reflecting the ball position of the default position 40
, because it's not the center.
Once the slider position is changed, the background colors are changed depending on the slider position.
That's the lesser problem, but the major problem is that the <output>
field no longer displays the new values. It's has been stuck to 40
.
How could it be fixed?