forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldSpectrum.vue
62 lines (56 loc) · 1.42 KB
/
fieldSpectrum.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
<template lang="pug">
input(type="text", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
</template>
<script>
/* global $ */
import abstractField from "../abstractField";
import { defaults } from "lodash";
export default {
name: "field-spectrum",
mixins: [abstractField],
data() {
return {
picker: null
};
},
watch: {
model() {
if (window.$ && window.$.fn.spectrum) {
this.picker.spectrum("set", this.value);
}
},
disabled(val) {
if (val) this.picker.spectrum("disable");
else this.picker.spectrum("enable");
}
},
mounted() {
this.$nextTick(function() {
if (window.$ && window.$.fn.spectrum) {
this.picker = $(this.$el)
.spectrum("destroy")
.spectrum(
defaults(this.fieldOptions, {
showInput: true,
showAlpha: true,
disabled: this.schema.disabled,
allowEmpty: !this.schema.required,
preferredFormat: "hex",
change: (color) => {
this.value = color ? color.toString() : null;
}
})
);
this.picker.spectrum("set", this.value);
} else {
console.warn(
"Spectrum color library is missing. Please download from http://bgrins.github.io/spectrum/ and load the script and CSS in the HTML head section!"
);
}
});
},
beforeDestroy() {
if (this.picker) this.picker.spectrum("destroy");
}
};
</script>