forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldNoUiSlider.vue
67 lines (56 loc) · 1.23 KB
/
fieldNoUiSlider.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template lang="jade">
div.slider(:disabled="disabled")
</template>
<script>
import abstractField from "./abstractField";
import { defaults } from "lodash";
export default {
mixins: [abstractField],
data() {
return {
slider: null
};
},
watch: {
model: function() {
if (window.noUiSlider) {
this.slider.noUiSlider.set(this.value);
}
}
},
methods: {
onChange(value) {
console.log(value);
if (value.length === 1) {
// Single value
this.value = parseFloat(value[0]);
} else {
// Array (range)
this.value = [parseFloat(value[0]), parseFloat(value[1])];
}
}
},
ready() {
if (window.noUiSlider) {
this.slider = this.$el;
window.noUiSlider.create(this.slider, defaults(this.schema.sliderOptions || {}, {
start: this.schema.min,
range: {
"min": this.schema.min,
"max": this.schema.max
}
}));
this.slider.noUiSlider.on("change", this.onChange.bind(this));
} else {
console.warn("noUiSlider is missing. Please download from https://github.com/leongersen/noUiSlider and load the script and CSS in the HTML head section!");
}
}
};
</script>
<style lang="sass">
.vue-form-generator .field-noUiSlider {
.field-wrap {
display: block;
}
}
</style>