Skip to content

Data exchange between components. #14381

Answered by brunnerh
0x1618 asked this question in Q&A
Nov 20, 2024 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

An approach that works through larger hierarchies would be a context.

The form sets an object as context that inputs can register themselves in, the form then can query the state of all registered inputs. To make this reactive, the object in the context needs to be stateful and the access to the validation state must also be reactive (i.e. a closure over a local $state variable; either a function or a getter).

But I am not really a fan of disabled submit buttons, they have some questionable accessibility characteristics. I prefer using native HTML validation which automatically prevents form submissions and shows accessible validation errors.


Context example:

// Form.svelte
const inputs = 

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@0x1618
Comment options

@brunnerh
Comment options

@0x1618
Comment options

@brunnerh
Comment options

Answer selected by 0x1618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants