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/slimy-oranges-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/vue-components": patch
---

Fixes default props decoding in OmegaForm
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ describe("OmegaForm withDefaultConstructor with persistency", () => {
addForm: null,
b: S.PositiveNumber(100)
}))),
fifth: S.Email
fifth: S.Email,
sixth: S.NumberFromString.pipe(S.withDefaultConstructor(() => 1000))
})

// Simulate query string parameters
// The persistency key is based on pathname and schema keys
// Format: pathname-key1-key2-key3...
// Keys from meta will be flattened with dot notation for nested fields
const pathname = "/test"
const keys = ["first", "second", "third", "fourth.addForm", "fourth.b", "fifth"]
const keys = ["first", "second", "third", "fourth.addForm", "fourth.b", "fifth", "sixth"]
const persistencyKey = `${pathname}-${keys.join("-")}`
const queryValue = JSON.stringify({ first: 1234 })

Expand Down Expand Up @@ -95,7 +96,8 @@ describe("OmegaForm withDefaultConstructor with persistency", () => {
fourth: {
addForm: null,
b: 100 // Default from withDefaultConstructor
}
},
sixth: "1000"
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ export const useOmegaForm = <
try {
// Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
if ("make" in schema && typeof (schema as any).make === "function") {
return (schema as any).make(defaultValues, { disableValidation: true })
const decoded = (schema as any).make(defaultValues, { disableValidation: true })
return S.encodeSync(schema.pipe(S.partial))(decoded)
}
} catch (error) {
console.warn("Could not extract schema constructor defaults:", error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<form.Form :subscribe="['values']">
<template #default="{ subscribedValues: { values } }">
<form.Input
label="aString"
name="aString"
/>
<form.Input
label="bString"
name="bString"
Expand All @@ -18,11 +22,11 @@ import { S } from "effect-app"
import { useOmegaForm } from "../../src"

const schema = S.Struct({
bString: S.PositiveNumber.pipe(S.withDefaultConstructor(() => S.PositiveNumber(2.0)))
// aString: S.NullOr(S.NonEmptyString).withDefault
aString: S.NullOr(S.NonEmptyString255).withDefault,
bString: S.NullOr(S.NonEmptyString255).withDefault
})
const defaultValues = {
bString: -2
aString: ""
}
const form = useOmegaForm(schema, {
onSubmit: async (values) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<template #default="{ subscribedValues: { errors, values: vvv } }">
<div>Errors: {{ errors }}</div>
<div>Values: {{ vvv }}</div>
<addForm.Input name="first" />
</template>
</addForm.Form>
</template>
Expand All @@ -29,7 +30,8 @@ const AddSchema = S.Struct({
addForm: null,
b: S.PositiveNumber(100)
}))),
fifth: S.Email
fifth: S.Email,
sixth: S.NumberFromString.pipe(S.withDefaultConstructor(() => 1000))
})

const addForm = useOmegaForm(
Expand Down