Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tangy-results-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/vue-components": patch
---

Forces form reset on tag change in OmegaForm Union
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defineProps<{
:field="inputProps.field as any"
:state="inputProps.state.value"
:name="name"
:form="form"
>
<template
v-for="(_, slotname) in $slots"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
import { type DeepKeys, type DeepValue } from "@tanstack/vue-form"
import { watch } from "vue"
import { type OmegaFieldInternalApi } from "./InputProps"
import { type useOmegaForm } from "./useOmegaForm"

const props = defineProps<{
state: DeepValue<From, Name>
field: OmegaFieldInternalApi<From, Name>
name?: DeepKeys<From>
form: ReturnType<typeof useOmegaForm<From, To>>
}>()

const values = props.form.useStore(({ values }) => values)

// Watch for _tag changes
watch(() => props.state, (newTag, oldTag) => {
if (newTag === null) {
props.field.setValue(null as DeepValue<From, Name>)
}
if (newTag !== oldTag) {
props.form.reset(values.value)
setTimeout(() => {
props.field.validate("change")
}, 0)
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-components/stories/OmegaForm/FormTaggedUnion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ import { useOmegaForm } from "../../src"

const form = useOmegaForm(
S.Struct({
aString: S.String,
aString: S.NonEmptyString255,
union: S.NullOr(
S.Union(
S.Struct({
a: S.NonEmptyString255,
common: S.String,
common: S.NonEmptyString255,
_tag: S.Literal("A")
}),
S.Struct({
b: S.Number,
common: S.String,
b: S.NonEmptyString255,
common: S.NonEmptyString255,
_tag: S.Literal("B")
})
)
Expand Down