forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldRangeSlider.vue
83 lines (73 loc) · 1.88 KB
/
fieldRangeSlider.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template lang="pug">
input(type="text", :autocomplete="fieldOptions.autocomplete", :data-disable="disabled", :data-max="fieldOptions.max", :data-min="fieldOptions.min", :data-step="fieldOptions.step", :placeholder="placeholder", :readonly="readonly", :name="inputName")
</template>
<script>
/* global $ */
import abstractField from "../abstractField";
import { defaults, isArray } from "lodash";
export default {
name: "field-rangeSlider",
mixins: [abstractField],
data() {
return {
slider: null
};
},
watch: {
model: function() {
if (window.$ && window.$.fn.ionRangeSlider) {
let valueFrom, valueTo;
if (isArray(this.value)) {
[valueFrom, valueTo] = this.value;
} else valueFrom = this.value;
if (this.slider) {
this.slider.update({
from: valueFrom,
to: valueTo
});
}
}
}
},
mounted() {
this.$nextTick(function() {
if (window.$ && window.$.fn.ionRangeSlider) {
let valueFrom, valueTo;
if (isArray(this.value)) {
[valueFrom, valueTo] = this.value;
} else valueFrom = this.value;
let self = this;
$(this.$el).ionRangeSlider(
defaults(this.fieldOptions, {
type: "single",
grid: true,
hide_min_max: true,
from: valueFrom,
to: valueTo,
onChange(slider) {
if (self.slider.options.type === "double") {
self.value = [slider.from, slider.to];
} else {
self.value = slider.from;
}
}
})
);
this.slider = $(this.$el).data("ionRangeSlider");
} else {
console.warn(
"ion.rangeSlider library is missing. Please download from https://github.com/IonDen/ion.rangeSlider and load the script and CSS in the HTML head section!"
);
}
});
},
beforeDestroy() {
if (this.slider) this.slider.destroy();
}
};
</script>
<style lang="scss">
.vue-form-generator .field-rangeSlider .irs {
width: 100%;
}
</style>