Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 30 additions & 20 deletions
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, getasobjGet } 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)

AltStyle によって変換されたページ (->オリジナル) /