Guide on creating a dual range slider with native HTML range input and Vue.js?

Seeking assistance in creating a double range slider with two handles for the native HTML input=range and Vue.js.

Current progress: https://jsfiddle.net/

Javascript (Vue.js)

var vm = new Vue({
  el: '#app',
  data: {
    minAngle: 10,
    maxAngle: 30
  },
  computed: {
    sliderMin: {
      get: function() {
        var val = this.minAngle;
        return val;
      },
      set: function(val) {
        if (val > this.maxAngle) {
          val = this.maxAngle;
        }
        this.minAngle = val;
        console.log("minAngle:" + this.minAngle + " maxAngle:" + this.maxAngle);
      }
    },
    sliderMax: {
      get: function() {
        var val = this.maxAngle;
        return val;
      },
      set: function(val) {
        if (val < this.minAngle) {
          val = this.minAngle;
        }
        this.maxAngle = val;
        console.log("minAngle:" + this.minAngle + " maxAngle:" + this.maxAngle);
      }
    }
  }
});

HTML

<div id="app">
  <input type="range" min="0" max="180" step="1" v-model="sliderMin">
  <input type="number" min="0" max="180" step="1" v-model="sliderMin">
  <input type="range" min="0" max="180" step="1" v-model="sliderMax">
  <input type="number" min="0" max="180" step="1" v-model="sliderMax">
</div>

Looking to restrict the range of the sliders to prevent values from going below the minimum. The goal is to have one slider on top of another using CSS, giving the illusion of a single slider with two handles. While aware of Vue components available for this, exploring the possibility without them.

Thank you in advance, Bogdan

Answer №1

Oh, the solution finally clicked for me! Turns out, it wasn't that far off after all :) Here's what worked:

HTML

<div id="app">
  <div class='range-slider'>
    <input type="range" min="0" max="180" step="1" v-model="sliderMin">
    <input type="number" min="0" max="180" step="1" v-model="sliderMin">
    <input type="range" min="0" max="180" step="1" v-model="sliderMax">
    <input type="number" min="0" max="180" step="1" v-model="sliderMax">
  </div>
</div>

Javascript (Vue)

var app = new Vue({
  el: '#app',
  data: {
    minPrice: "500",
    maxPrice: "50000",
    minValue: "25000"
  },
  methods: {
    slider: function() {
      if (this.minPrice > this.maxPrice) {
        var tmp = this.maxPrice;
        this.maxPrice = this.minPrice;
        this.minPrice = tmp;
      }
    }
  }
});

CSS

.range-slider {
  width: 300px;
  margin: auto;
  text-align: center;
  position: relative;
  height: 6em;
}

.range-slider input[type=range] {
  position: absolute;
  left: 0;
  bottom: 0;
}

input[type=number] {
  border: 1px solid #ddd;
  text-align: center;
  font-size: 1.6em;
  -moz-appearance: textfield;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

input[type=number]:invalid,
input[type=number]:out-of-range {
  border: 2px solid #ff6347;
}

input[type=range] {
  -webkit-appearance: none;
  width: 100%;
}

... (CSS continues)

Fiddle:

https://jsfiddle.net/bogdanb86/3dr9ktxc/28/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extracting information from an ENORMOUS Array

Let's start with my code snippet, featuring an array: var UserProfiles = [{ userProfileID: 1, firstName: 'Austin', lastName: 'Hunter', email: 'test', token: '', platform: 'android ...

What is the process for sending a token using Passport-VKontakte for social authentication?

I have integrated VK auth in my app, but in order to identify the site visitor, I need to send them a token when they click on auth vk. How can I send this token to the user using passport-vkontakte? app.get('/auth/vk', passport.authenticate(& ...

Using Angular to share JSON data efficiently between controllers

Greetings everyone, I am a beginner in Angular and not very skilled with JavaScript. The issue I'm facing is that although this setup successfully fetches the JSON data, whenever I modify certain object properties, they revert back to their original s ...

Warning in Jest / Vue test utils: Attempting to use a method from a subcomponent scoped slot as an event handler for "click" but receiving an undefined value

I am currently working on testing one of my components that calls a subcomponent known as b-modal. The component being tested utilizes scoped slots from b-modal to access the close() method and then attaches it to another event listener. Here is what it l ...

Customize the appearance of the Vue.js datepicker starting from today's date

I am currently using the vue-datepicker component to display a date input field in my form. I want to set the default date to the current day and disable the selection of past dates. Additionally, I need to change the language of the component but it seems ...

Modifying React routes does not alter the path or outlet of the routes

On the app.js file, I have the following routes: import React from "react"; import Login from "./pages/Login"; import { BrowserRouter, Routes, Route } from "react-router-dom"; import Dashboard from "./pages/Dashboard" ...

Code activates the wrong function

Below is a snippet of HTML and JS code for handling alerts: HTML: <button onclick="alertFunction()">Display Choose Option Modal</button> <button onclick="alertFunction2()">Display Veloce Modal</button> JS: function alertFunct ...

What is the best way to define a constant within a map function?

I have a VueJs computed function called linhas() that populates the rows of my DataTable. I am struggling with opening up this function to assign a value to "this.grupo", so that I can avoid using it the same way as I do with "this.maquinas". As a beginner ...

Keying objects based on the values of an array

Given the array: const arr = ['foo', 'bar', 'bax']; I am looking to create an object using the array entries: const obj = { foo: true, bar: true, bax: false, fax: true, // TypeScript should display an error here becau ...

Obtaining a file that includes a selection of documents that correspond to a specific search criteria, along with the overall number of

Is it possible to query a collection to retrieve both a limited number of documents matching a query and the total amount of documents that match the query at the same time? This is the desired result: { result : [ { _id:null, ...

Can you show me how to reposition the button alongside the sidebar?

Currently working on a college project centered around developing a personal website and I could use some assistance with aligning the Button to move along with the sidebar. When clicking on the hamburger menu, the sidebar shifts to the right, and then ba ...

Efficiently align a Modal in React without the need to rewrite any code

In my application, I have a class called InventoryView that is responsible for displaying a list of stock items. The class is structured as follows: class InventoryView extends Component { ... render() { ... { consumableItemsArray.map((ro ...

Adjust the user interface in response to a modification in a directive attribute within AngularJs

I am currently facing challenges with data binding in AngularJs. Within my .html file, I have the following markup that includes a custom directive: <my-directive ng-repeat="i in object" attr-1="{{i.some_variable}}"></my-directive> Important ...

What is the best way for a Vue component to update a list in a different component that it's not directly related to?

There are two main components in my project: <filter-controls></filter-controls> <data-list></data-list> The <data-list> component contains a list of items, such as ingredients, that can be filtered based on user input. Me ...

Embed a three.js scene into a grid layout using Bootstrap

Trying to embed a three.js scene with toggle switches inside a Bootstrap grid. The issue is that my canvas, which is inside a column, doesn't align properly with the text column on the same row. Any assistance would be greatly appreciated. Preview: V ...

Techniques for manipulating multiple circles with JavaScript

After creating a series of circles with d3, I successfully implemented the functionality to drag individual circles and track their positions. var width= 800; var height=600; svg= d3.select("body").select(".div1").append("svg") ...

A JavaScript variable... cannot access

Can anybody explain to me the reason behind this reference not functioning properly? let linkId = $(this).attr("data-id"); //retrieve the id data when a tag is clicked $(".wrapper").find("section[id=linkId]").css({"background-color": "red"}); ...

Consider null values in mapping an array in ES6

I have successfully mapped an array. const faculty = props.faculty; {(faculty.science_department || []).map(science_dep => ( <div className="row"> <p>{science_dep.name} : {science_dep.start_date}</p> </div> ))} ...

Struggling to make PayPal Cordova Plugin function properly in both production and sandbox modes

While using the cordova paypal plugin and switching to sandbox mode, I encountered an error. The plugin can be found at https://github.com/paypal/PayPal-Cordova-Plugin https://i.stack.imgur.com/lD2EH.png Running the plugin in PayPalEnvironmentNoNetwork m ...

Ways to retrieve a grandchild element of a specific element using its tag name

I'm struggling to access elements that are nested within various levels of parent elements with and without IDs. The usual method getElementByTagName doesn't seem to be working for me, especially when the target element is three levels deep. Is t ...