Skip to content

Commit 2024204

Browse files
committed
fixes an issue with fieldPikaday modifying the field schema and attaching this.$el to it, the pikadayOptions are now stored as this.options and created with defaults({}, this.schema.pikadayOptions, {...}) to prevent this
1 parent a484031 commit 2024204

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/fields/optional/fieldPikaday.vue

+30-20
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,56 @@
44

55
<script>
66
import abstractField from "../abstractField";
7-
import { defaults } from "lodash";
7+
import { defaults, get as objGet } from "lodash";
88
import dateFieldHelper from "../../utils/dateFieldHelper";
99
1010
let inputFormat = "YYYY-MM-DD";
1111
1212
export default {
13-
mixins: [abstractField],
13+
mixins: [ abstractField ],
1414
data() {
15-
return { picker: null };
15+
return {
16+
picker: null,
17+
options: null
18+
};
1619
},
1720
1821
methods: {
1922
getDateFormat() {
20-
if (this.schema.pikadayOptions && this.schema.pikadayOptions.format) return this.schema.pikadayOptions.format;
21-
else return inputFormat;
23+
return objGet(this.schema, 'pikadayOptions.format', inputFormat);
2224
},
25+
...dateFieldHelper,
26+
initialize(options) {
27+
if(this.picker && this.picker.destroy) {
28+
// if an existing picker is already set, destroy it first
29+
this.picker.destroy();
30+
}
2331
24-
...dateFieldHelper
25-
},
26-
27-
mounted() {
28-
this.$nextTick(() => {
29-
if (window.Pikaday) {
30-
this.picker = new window.Pikaday(
31-
defaults(this.schema.pikadayOptions || {}, {
32+
this.$nextTick(() => {
33+
if (window.Pikaday) {
34+
this.options = defaults({}, options, {
3235
field: this.$el, // bind the datepicker to a form field
3336
onSelect: () => {
3437
this.value = this.picker.toString();
3538
}
3639
// trigger: , // use a different element to trigger opening the datepicker, see [trigger example][] (default to `field`)
37-
})
38-
);
39-
} else {
40-
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
41-
}
42-
});
40+
});
41+
this.picker = new window.Pikaday(this.options);
42+
} else {
43+
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
44+
}
45+
});
46+
}
47+
},
48+
49+
mounted() {
50+
this.initialize(objGet(this.schema, "pikadayOptions", {}));
4351
},
4452
4553
beforeDestroy() {
46-
if (this.picker) this.picker.destroy();
54+
if (this.picker) {
55+
this.picker.destroy();
56+
}
4757
}
4858
};
4959
</script>

0 commit comments

Comments
 (0)