mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-22 00:01:34 +00:00
fix: clear datetime input in schedule sets input to null (#7358)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { format, isValid, parse } from 'date-fns'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
|
||||
export let value: string | undefined = undefined
|
||||
export let value: string | null | undefined = undefined
|
||||
export let autofocus: boolean | null = false
|
||||
export let minDate: string | undefined = undefined
|
||||
export let maxDate: string | undefined = undefined
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
function computeDate(value: string | undefined) {
|
||||
function computeDate(value: string | null | undefined) {
|
||||
if (dateFormat === undefined) {
|
||||
dateFormat = defaultDateFormat
|
||||
}
|
||||
@@ -83,6 +83,9 @@
|
||||
on:change={() => {
|
||||
if (date) {
|
||||
updateValue(date)
|
||||
} else {
|
||||
value = null
|
||||
dispatch('change', value)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
interface Props {
|
||||
// import ToggleButton from './common/toggleButton-v2/ToggleButton.svelte'
|
||||
value?: string | undefined
|
||||
value?: string | null | undefined
|
||||
clearable?: boolean
|
||||
autofocus?: boolean | null
|
||||
useDropdown?: boolean
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
// let format: 'local' | 'utc' = 'local'
|
||||
|
||||
function parseValue(value: string | undefined = undefined) {
|
||||
function parseValue(value: string | null | undefined = undefined) {
|
||||
let dateFromValue: Date | undefined = value ? new Date(value) : undefined
|
||||
if (!isValidDate(dateFromValue)) {
|
||||
date = undefined
|
||||
@@ -76,6 +76,13 @@
|
||||
let initialTime = untrack(() => time)
|
||||
|
||||
function parseDateAndTime(date: string | undefined, time: string | undefined) {
|
||||
// Handle cleared date - if date is empty string (user cleared) but value still has a value
|
||||
if (date === '' && value) {
|
||||
value = null
|
||||
dispatchIfMounted('change', value)
|
||||
return
|
||||
}
|
||||
|
||||
if (date && time && (initialDate != date || initialTime != time)) {
|
||||
let newDate = new Date(timezone === 'local' ? `${date}T${time}` : `${date}T${time}Z`)
|
||||
if (newDate.toString() === 'Invalid Date') return
|
||||
@@ -178,7 +185,7 @@
|
||||
wrapperClasses="h-full"
|
||||
{disabled}
|
||||
on:click={() => {
|
||||
value = undefined
|
||||
value = null
|
||||
dispatch('clear')
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user