Skip to content

Schedule Picker

A time of day and, optionally, days of the week as a group of toggle buttons. The value is plain data.

Decision

When Use
A daily or weekly run time Schedule Picker
An interval, such as every 5 minutes A Number Unit Field or a Duration Field
Weekly windows with a start and an end Access Schedule
One start and end Time Range Field

Usage

import { createSchedulePicker } from './configurationpage?name=myplugin_stolon.js';

var run = createSchedulePicker({ value: { time: '02:30', days: [1, 3, 5] }, onChange: function (value) { config.Schedule = value; } });
container.appendChild(run.element);

Classes: stolon-schedule, stolon-schedule-days. The handle is { element, getValue, setValue, setSize, isValid, destroy }.

Parts: stolon-schedule-time.

States and Modifiers

  • The value is { time: "HH:mm", days: [0 to 6] }, with 0 for Sunday. getValue() returns the days sorted from 0, and time is '' while the input is empty.
  • showTime: false and showDays: false hide a part. weekStart: 1 starts the week on Monday.
  • The days are the stolon-toggle-group of buttons, each with aria-pressed.
  • required and validate({ time, days }) check through the validation core, with the message under the picker. isValid() checks and shows it.
  • The labels default to "Time", "Days", and "Sun" to "Sat". timeLabel, daysLabel, and dayLabels replace them. A dayLabels with fewer than seven labels falls back to the defaults.
  • setValue keeps each whole number day from 0 to 6 once and ignores the rest.
  • size is small, medium (default), or large, and sizes its fields on the size scale. setSize(size) changes it later.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createSchedulePicker

function createSchedulePicker(options?: SchedulePickerOptions): SchedulePickerHandle

A time of day and, optionally, days of the week as a group of toggle buttons. The value is plain data, a time as "HH:mm" and days as numbers from 0 for Sunday to 6 for Saturday.

Option Type What it does
value Partial<SchedulePickerValue> | null { time: 'HH:mm', days: array of 0 to 6 } [optional]
showTime boolean false hides the time input (default true)
showDays boolean false hides the day toggles (default true)
weekStart number 0 starts the week on Sunday and 1 on Monday (default 0)
timeLabel string aria-label of the time input (default 'Time')
daysLabel string aria-label of the day group (default 'Days')
dayLabels string[] array of seven labels from Sunday (default 'Sun' to 'Sat', and a shorter array falls back to the default)
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
required boolean true makes the time required, checked through the validation core (default false)
validate (value: SchedulePickerValue): string | null | undefined function({ time, days }) returning an error sentence, or an empty value when valid, shown under the time [optional]
onChange (value: SchedulePickerValue): void function({ time, days }) [optional]
Handle member Type
getValue (): SchedulePickerValue
setValue (next?: Partial<SchedulePickerValue> | null): void
setSize (size?: 'small' | 'medium' | 'large'): void
isValid (): boolean
destroy (): void
Type What it is
SchedulePickerValue A time as "HH:mm", or '' while empty, and days as numbers from 0 for Sunday to 6 for Saturday.
Class What it looks like
stolon-schedule Time input and day toggles, side by side where there is room and stacked where there is not

Example

Example Code

<!-- title: Schedule Picker -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
const note = document.createElement('div');
note.className = 'stolon-status-text';
mount.appendChild(base.createSchedulePicker({ value: { time: '02:30', days: [1, 3, 5] }, onChange: (v) => { note.textContent = JSON.stringify(v); } }).element);
mount.appendChild(note);
</script>