brad
September 15, 2025, 11:38pm
1
I have a datepicker that I would only like dates from the database selectable.
<input id="searchDate" name="searchDate" type="text" class="form-control form-control-sm" is="dmx-date-picker" opens="left" dmx-bind:value="varChangeDate.datetime" format="YYYY-MM-DD" dmx-bind:customdates="dates.data.query" customdates-start="log_date" customdates-end="log_date">
But it still has all dates enabled? I want all dates that are not in the database disabled. Can this be done?
Teodor
September 16, 2025, 2:49pm
3
Custom dates, which you are using in your example are dates that you want to style differently, than the rest. You can apply a custom class to them.
Currently the date picker does not have an option to enable just the dates, returned by a data source and disable all the rest.
Teodor
September 16, 2025, 3:00pm
4
You can do it with some custom code though.
Create a file called custom.js and place it in a folder, for example the /js/ folder in your site root.
Add the following content inside it:
dmx.Component('date-picker2', {
extends: 'date-picker',
attributes: {
'onlycustom': {
type: Boolean,
default: false
}
},
_isInvalidDate(date) {
if (this.props.onlycustom) {
const isCustom = this.props.customdates.some(range => this._isInRange(date, range, this.props.customdatesStart, this.props.customdatesEnd));
return !isCustom;
}
if (this.props.disableweekends && (date.day() === 0 || date.day() === 6)) return true;
return this.props.invaliddates.some(range => this._isInRange(date, range, this.props.invaliddatesStart, this.props.invaliddatesEnd));
},
});
Include this file before the closing </head> tag with the correct path and defer attribute:
<script src="/js/custom.js" defer></script>
And on your page change the date picker code from:
<input id="searchDate" name="searchDate" type="text" class="form-control form-control-sm" is="dmx-date-picker" opens="left" dmx-bind:value="varChangeDate.datetime" format="YYYY-MM-DD" dmx-bind:customdates="dates.data.query" customdates-start="log_date" customdates-end="log_date">
to
<input id="searchDate" name="searchDate" type="text" class="form-control form-control-sm" is="dmx-date-picker2" opens="left" dmx-bind:value="varChangeDate.datetime" format="YYYY-MM-DD" dmx-bind:customdates="dates.data.query" customdates-start="log_date" customdates-end="log_date" onlycustom="true">
this will make only the custom dates selectable.
brad
September 16, 2025, 3:39pm
5
Worked like a charm! Perfect, thank you!
patrick
September 16, 2025, 3:40pm
6
We'll add the extra property in the next update.
1 Like
Teodor
September 18, 2025, 3:20pm
7
The option has been added to the datepicker in Wappler 7.3.2, so you don't need the custoom code any more. Just remove the custom date picker and re-add it, then enable the option from the UI.