Skip to content

TimePicker

Rules

Basic Example

js
const rule = {
    type: "TimePicker",
    field: "section_time",
    title: "Activity Time",
    value: ''
}

Props Configuration Examples

Custom Format

js
const rule = {
    type: "TimePicker",
    field: "time",
    title: "Select Time",
    value: null,
    props: {
        format: "HH:mm:ss",
        placeholder: "Select time",
        clearable: true,
    }
}

12-Hour Format

js
const rule = {
    type: "TimePicker",
    field: "time",
    title: "Select Time",
    value: null,
    props: {
        use12Hours: true,
        format: "hh:mm:ss a",
        placeholder: "Select time",
    }
}

Limit Time Range

js
const rule = {
    type: "TimePicker",
    field: "workTime",
    title: "Work Time",
    value: null,
    props: {
        format: "HH:mm",
        placeholder: "Select time",
        hours: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
        minutes: [0, 15, 30, 45],
    }
}

Disable Specific Times

js
const rule = {
    type: "TimePicker",
    field: "time",
    title: "Select Time",
    value: null,
    props: {
        format: "HH:mm:ss",
        placeholder: "Select time",
        isHourDisabled: (hour) => hour < 9 || hour > 18,
        isMinuteDisabled: (minute, hour) => {
            if (hour === 12) {
                return minute < 30;
            }
            return false;
        },
    }
}

Events Examples

Handle Time Changes

js
const rule = {
    type: "TimePicker",
    field: "time",
    title: "Select Time",
    value: null,
    props: {
        format: "HH:mm:ss",
        placeholder: "Select time",
        clearable: true,
    },
    on: {
        'update:value': (value, formattedValue) => {
            console.log('Time changed:', value, formattedValue);
        },
        blur: () => {
            console.log('Lost focus');
        },
        focus: () => {
            console.log('Gained focus');
        },
    },
}

Linkage Update After Time Selection

js
const rule = [
    {
        type: "TimePicker",
        field: "startTime",
        title: "Start Time",
        value: null,
        props: {
            format: "HH:mm",
            placeholder: "Select start time",
        },
        inject: true,
        on: {
            'update:value': ($inject, value) => {
                // Set end time to start time + 2 hours
                if (value) {
                    const endTime = value + 2 * 60 * 60 * 1000;
                    $inject.api.setValue('endTime', endTime);
                }
            },
        },
    },
    {
        type: "TimePicker",
        field: "endTime",
        title: "End Time",
        value: null,
        props: {
            format: "HH:mm",
            placeholder: "Select end time",
        },
    },
]

Complete configuration items: naive-ui_TimePicker

value :Number | String

Props

NameTypeDefault ValueDescriptionVersion
actionsArray<'now' | 'confirm'> | null['now', 'confirm']Supported operations in Time Picker
clearablebooleanfalseWhether it can be cleared
disabledbooleanfalseWhether disabled
formatstring'HH:mm:ss'Time format string, see format for details
formatted-valuestring | nullundefinedFormatted value2.24.0
hoursnumber | number[]undefinedSpecify displayed hours through array. When value is number, it will be treated as time step
minutesnumber | number[]undefinedSpecify displayed minutes through array. When value is number, it will be treated as time step
secondsnumber | number[]undefinedSpecify displayed seconds through array. When value is number, it will be treated as time step
input-readonlybooleanfalseSet input box to readonly (avoid opening virtual keyboard on mobile devices)
is-hour-disabled(hour: number) => boolean() => falseCallback function for disabling hours
is-minute-disabled(minute: number, hour: number) => boolean() => falseCallback function for disabling minutes
is-second-disabled(second: number, minute: number, hour: number) => boolean() => falseCallback function for disabling seconds
placeholderstring'Select Time'Placeholder for select box
placement'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' | 'bottom-start'Popup position of Time Picker panel2.25.0
size'small' | 'medium' | 'large''medium'Size of select box
use-12-hoursbooleanfalseWhether to use 12-hour format panel
value-formatstringFollows formatFormat of formatted value2.24.0
on-blur() => voidundefinedCallback when select box loses focus
on-focus() => voidundefinedCallback when select box gains focus
on-update:formatted-value(value: number | null, timestampValue: number | null) => voidundefinedCallback when formatted value changes2.24.0
on-update:value(value: number | null, formattedValue: string | null) => voidundefinedCallback when value changesformattedValue 2.24.0

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.