Yarn add nouislider
(be careful that students don't npm install)- Add js to /application.js or on top of your plugins/slider.js
'import noUiSlider from 'nouislider';
- Add CSS to /application.scss
@import nouislider/distribute/nouislider';
- Add a element to the html with a precise id
<div id="slider"></div>
- Select the element in js and create a slider
const slider = document.getElementById('slider'); noUiSlider.create(slider, { start: [20, 80], connect: true, range: { 'min': 0, 'max': 100 } });
- Add 2 hidden input fields in your form
- Listen to the change on the slider
- Get the value on change => you get a [ "min", "max"] if it is a range 3 Set the value of the two hidden inputs
Learn how to use JS plugins with Rails 5.1, Webpacker and Yarn. Follow the example to install Flatpickr as a datepicker for your app
tuto/ article made by a Teacher, Rui Freitas