Limit time in v-calendar datepicker

Viewed 548

I am working on a project where user request for appointment. I am using v-calendar which uses the datepicker.

I am facing a issue where user can request for appointment any time/ 24 hours which I need to set only for 9am - 5pm. I can see that we can limit date in date picker by using something like :max-date="value" but could not found how to limit the time.

Here is the working fiddle

some code from the project

    name="appointment-date"
    v-model="appointment_date"
    mode="dateTime"
    :is24hr="false"
    :min-date="currentDate"
    :model-config="dateTimePickerConfig"
    :popover="{
    visibility: 'click',
    placement:  'auto',
 }"
    :masks="{ inputDateTime: 'MM/DD/YYYY h:mmA'}">
    <template v-slot="{ inputValue, inputEvents }">
        <div class="form-icon ">
            <input-component
                :value="inputValue"
                v-on="inputEvents"
                placeholder="MM-DD-YYYY h:mmA"
            />
            <Icon name="date-time"/>
        </div>
    </template>
</date-picker>

Your help to solve the problem will be higly appreciated.

Thank you.

1 Answers

If I understood you well, you want to restrict picking specific hours. This is possible with v-calendar with the following property:

<v-date-picker v-model="date" :valid-hours="[0,3,4,5,8,16,20]" is24hr />

Please note the :valid-hours attribute. You can provide which hours should be available for the user to pick. If you want to allow them to pick minutes in specific 'intervals' you can use following as well:

<v-date-picker v-model="date" mode="dateTime" :minute-increment="15" />

Note :minute-increment property. This will allow user to pick between '15 minutes. So available numbers will be 00, 15, 30, 45. You can play with it.

Unfortunately, there is no way to disable minutes, which makes me sad. As if someone books appointment at 9:15 AM you would rather want to 'disable' 9:15 AM for next users. You could disable whole hour (9 AM) but not specifically 9:15, so that 9:00, 9:30 and 9:45 would still be available. At least I don't know any easy way.

Hope this helps anyone.

================ UPDATE =================
Note that v-calendar added those additional properties in specific v-calendar version. I've been using it with v2.4., seems like v2.3. does not have it yet.

Related