fix: add disabled support for boolean
This commit is contained in:
parent
86d265dee4
commit
0c77d1943f
|
|
@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from '
|
||||||
import { Switch } from '@/lib/registry/default/ui/switch'
|
import { Switch } from '@/lib/registry/default/ui/switch'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
const props = defineProps<FieldProps>()
|
const props = defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S
|
||||||
<component
|
<component
|
||||||
:is="booleanComponent"
|
:is="booleanComponent"
|
||||||
v-bind="{ ...slotProps.componentField }"
|
v-bind="{ ...slotProps.componentField }"
|
||||||
:disabled="disabled"
|
:disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled"
|
||||||
:checked="slotProps.componentField.modelValue"
|
:checked="slotProps.componentField.modelValue"
|
||||||
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -169,3 +169,20 @@ export function getFromPath<TValue = unknown, TFallback = TValue>(
|
||||||
|
|
||||||
return resolvedValue as TValue | undefined
|
return resolvedValue as TValue | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Booleanish = boolean | 'true' | 'false'
|
||||||
|
|
||||||
|
export function booleanishToBoolean(value: Booleanish) {
|
||||||
|
switch (value) {
|
||||||
|
case 'true':
|
||||||
|
case true:
|
||||||
|
return true
|
||||||
|
case 'false':
|
||||||
|
case false:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function maybeBooleanishToBoolean(value?: Booleanish) {
|
||||||
|
return value ? booleanishToBoolean(value) : undefined
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { FormControl, FormDescription, FormField, FormItem, FormMessage } from '
|
||||||
import { Switch } from '@/lib/registry/new-york/ui/switch'
|
import { Switch } from '@/lib/registry/new-york/ui/switch'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import AutoFormLabel from './AutoFormLabel.vue'
|
import AutoFormLabel from './AutoFormLabel.vue'
|
||||||
import { beautifyObjectName } from './utils'
|
import { beautifyObjectName, maybeBooleanishToBoolean } from './utils'
|
||||||
|
|
||||||
const props = defineProps<FieldProps>()
|
const props = defineProps<FieldProps>()
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ const booleanComponent = computed(() => props.config?.component === 'switch' ? S
|
||||||
<component
|
<component
|
||||||
:is="booleanComponent"
|
:is="booleanComponent"
|
||||||
v-bind="{ ...slotProps.componentField }"
|
v-bind="{ ...slotProps.componentField }"
|
||||||
:disabled="disabled"
|
:disabled="maybeBooleanishToBoolean(config?.inputProps?.disabled) ?? disabled"
|
||||||
:checked="slotProps.componentField.modelValue"
|
:checked="slotProps.componentField.modelValue"
|
||||||
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
@update:checked="slotProps.componentField['onUpdate:modelValue']"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -169,3 +169,20 @@ export function getFromPath<TValue = unknown, TFallback = TValue>(
|
||||||
|
|
||||||
return resolvedValue as TValue | undefined
|
return resolvedValue as TValue | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Booleanish = boolean | 'true' | 'false'
|
||||||
|
|
||||||
|
export function booleanishToBoolean(value: Booleanish) {
|
||||||
|
switch (value) {
|
||||||
|
case 'true':
|
||||||
|
case true:
|
||||||
|
return true
|
||||||
|
case 'false':
|
||||||
|
case false:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function maybeBooleanishToBoolean(value?: Booleanish) {
|
||||||
|
return value ? booleanishToBoolean(value) : undefined
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user