I learned to make a plugin to show the day-name before a data field, and it works. The code is below. I like some help to see if I did it the right way.
It’s all new to me, I tried a lot of things and my question is:
Is this the best way to extend the date field and fill the ‘before’ with a value?
It works on my machine, but I’m a bit worried I have omitted some crucial code.
extra question:
I could not get the dayjs library to output day names in my language, despite the 'locale' => 'nl_NL.utf-8'
in my kirby config.php file. So I created an array of names. Is there a better way?
Thanks,
René
#sandbox.yml
sections:
fields:
type: fields
fields:
datewithdayname:
label: Datumveld met dagnaam
type: DateFieldwithDayName
showday: true
display: DD-MM-YY
time: false
calendar: true
/* site/plugins/DateFieldwithDayName/src/index.js */
import NewField from "./components/DateFieldExtra.vue";
window.panel.plugin("rlb/DateFieldwithDayName", {
fields: {
DateFieldwithDayName: NewField
}
});
<!-- site/plugins/DateFieldwithDayName/index.php -->
<?php
Kirby::plugin('rlb/DateFieldwithDayName', [
'fields' => [
'DateFieldwithDayName' => [
'extends' => 'date',
'props' => [
'showday' => function(Bool $showday)
{
return $showday;
}
]
]
],
]);
<!-- site/plugins/DateFieldwithDayName/src/components/DateFieldExtra.vue -->
<template>
<k-date-field :before="getDayName" v-bind="$props" @input="onDateInput" />
</template>
<script>
export default {
extends: "k-date-field",
props: {
showday: {
type: Boolean,
default: true
},
},
computed: {
getDayName() {
if (this.showday)
{
const dayNameList = ['zondag', 'maandag', 'dinsdag', 'woendag', 'donderdag', 'vrijdag', 'zaterdag'];
const dayNumber = this.$library.dayjs(this.value).format('d');
return dayNameList[dayNumber];
} else {
return "";
}
}
},
}
</script>
```**strong text**