Datepicker - Only dates from database

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">

Screenshot 2025-09-15 at 5.05.36 PM

But it still has all dates enabled? I want all dates that are not in the database disabled. Can this be done?

I think this is a bug ?

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.

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.

Worked like a charm! Perfect, thank you! :beers: :beers:

We'll add the extra property in the next update.

1 Like

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.