Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add explicit support for default values in input fields #1540

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Nov 5, 2024

We use the yup validation and value to set default values, but this seems fragile and prone to break as result of side effects from other code changes.

This pr adds an explicit defaultValue property to inputs.

@riccardobl riccardobl mentioned this pull request Nov 5, 2024
@huumn
Copy link
Member

huumn commented Nov 5, 2024

I think in this case we want to use the initial object prop in Form.

For wallets, we'd do this here:

const initial = useMemo(() => {
const initial = wallet?.def.fields.reduce((acc, field) => {
// We still need to run over all wallet fields via reduce
// even though we use wallet.config as the initial value
// since wallet.config is empty when wallet is not configured.
// Also, wallet.config includes general fields like
// 'enabled' and 'priority' which are not defined in wallet.fields.
return {
...acc,
[field.name]: wallet?.config?.[field.name] || ''
}
}, wallet?.config)
if (wallet?.def.fields.every(f => f.clientOnly)) {
return initial
}

Changing this line

[field.name]: wallet?.config?.[field.name] || ''
to:

[field.name]: wallet?.config?.[field.name] || field.defaultValue || ''

@huumn
Copy link
Member

huumn commented Nov 5, 2024

I'm finishing this up right now

@huumn
Copy link
Member

huumn commented Nov 5, 2024

lol you beat me to it

@huumn huumn merged commit 532abcb into stackernews:master Nov 5, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants