Replies: 1 comment 2 replies
|
To clear things up, I haven’t fully integrated Architecturally, I have built my own internal Design System with components like
Because of this design, I need
To give you a real-world example of why this matters, let's look at chess. In chess, game states are shared using a FEN string, which looks like this:
In my app, I have an I am using a custom composable that leverages VueUse’s export function useFen(defaultFen: MaybeRefOrGetter<string> = FEN.start) {
const fen = useRouteQuery<string>('fen', defaultFen);
const fenGroups = computed(() => FEN_REGEX.exec(fen.value)?.groups);
const turn = computed({
get: () => fenGroups.value?.turn ?? 'w',
set: (newTurn) =>
(fen.value = fen.value.replace(FEN_REGEX, `$<board> ${newTurn} $<castle> $<enPassant> $<halfMove> $<fullMove>`)),
});
const castle = useCastle(fen, () => fenGroups.value?.castle);
const enPassant = computed({
get: () => fenGroups.value?.enPassant ?? '-',
set: (newEnPassant) =>
(fen.value = fen.value.replace(FEN_REGEX, `$<board> $<turn> $<castle> ${newEnPassant} $<halfMove> $<fullMove>`)),
});
const halfMove = computed({
get: () => fenGroups.value?.halfMove ?? '0',
set: (newHalfMove) =>
(fen.value = fen.value.replace(FEN_REGEX, `$<board> $<turn> $<castle> $<enPassant> ${newHalfMove} $<fullMove>`)),
});
const fullMove = computed({
get: () => fenGroups.value?.fullMove ?? '1',
set: (newFullMove) =>
(fen.value = fen.value.replace(FEN_REGEX, `$<board> $<turn> $<castle> $<enPassant> $<halfMove> ${newFullMove}`)),
});
return {
value: fen,
turn,
castle,
enPassant,
halfMove,
fullMove,
};
}In
Once the user is satisfied with the position they created or modified, they navigate back to the Coming from Angular, the framework makes no distinction between a "traditional" form and a form bound to a reactive model (using Signals). You get a single, unifed API for both. That is exactly what I am looking for here: a common, uniform pattern in Vue/vee-validate that handles both standard forms and model-driven/URL-driven forms seamlessly. |
Uh oh!
There was an error while loading. Please reload this page.
In a large-scale application, I am using vee-validate to handle all forms, with valibot for the validation schemas.
I need to support two different form behaviors:
useFormapproach).2.A form where the values are fully synchronized with an external reactive model (a
ref).I am struggling to find the best way to achieve this second pattern. Ideally, I would love to pass a
refdirectly to the form controller to drive its values, similar to:Where:
myModelchanges externally, the form fields and their validation states update accordingly.myModelis updated instantly.As far as I know, vee-validate does not natively support passing a
refto drive the whole form values this way (the state remains internal to vee-validate).Coming from Angular, this mirrors how the new Signal Forms API works, and it is a workflow I find incredibly robust and convenient for managing forms.
Right now, the only options I see are:
useSyncedFormfrom scratch to sync the vee-validate form instance with aref.Is there an idiomatic way or a specific pattern to achieve this bi-directional synchronization between an external
refand vee-validate's internal state without adding a lot of manual boilerplate?All reactions