Skip to content

fixes an issue with fieldPikaday modifying the field schema and attac… #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions src/fields/optional/fieldPikaday.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,56 @@

<script>
import abstractField from "../abstractField";
import { defaults } from "lodash";
import { defaults, get as objGet } from "lodash";
import dateFieldHelper from "../../utils/dateFieldHelper";

let inputFormat = "YYYY-MM-DD";

export default {
mixins: [abstractField],
mixins: [ abstractField ],
data() {
return { picker: null };
return {
picker: null,
options: null
};
},

methods: {
getDateFormat() {
if (this.schema.pikadayOptions && this.schema.pikadayOptions.format) return this.schema.pikadayOptions.format;
else return inputFormat;
return objGet(this.schema, "pikadayOptions.format", inputFormat);
},
...dateFieldHelper,
initialize(options) {
if(this.picker && this.picker.destroy) {
// if an existing picker is already set, destroy it first
this.picker.destroy();
}

...dateFieldHelper
},

mounted() {
this.$nextTick(() => {
if (window.Pikaday) {
this.picker = new window.Pikaday(
defaults(this.schema.pikadayOptions || {}, {
this.$nextTick(() => {
if (window.Pikaday) {
this.options = defaults({}, options, {
field: this.$el, // bind the datepicker to a form field
onSelect: () => {
this.value = this.picker.toString();
}
// trigger: , // use a different element to trigger opening the datepicker, see [trigger example][] (default to `field`)
})
);
} else {
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
}
});
});
this.picker = new window.Pikaday(this.options);
} else {
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
}
});
}
},

mounted() {
this.initialize(objGet(this.schema, "pikadayOptions", {}));
},

beforeDestroy() {
if (this.picker) this.picker.destroy();
if (this.picker) {
this.picker.destroy();
}
}
};
</script>
Expand Down