final-form / final-form/react-final-form

Why form.change can't change value if there is not a corresponding field ?

Open
#242 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

Hello !
i tried to change my form values using form.change, but it seems to work only if there is a corresponding field. Is there any reason to not allow to change freely values and add new keys ?

My use case : i have a "country" autocomplete text fields.
When a "country" is selected, autocomplete give me a complex object about the country like this
```js
{
name: "France",
code: "FR",
...otherProperties
}
```

and i would like to add this to my submitted values. Do not care so much about what there is in my autocomplete input, i cared much about the object, return by the autocomplete suggestion list.

For now i am playing with "format" prop and return an object as a value on onChange, but it feels somehow hackish to me ?
```
suggestion.label}
className="is-large"
autocompleteCallback={getCountriesByName}
/>
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the form.change entry point and the Field value flow, including the format and onChange workaround shown in the issue. Determine the intended behavior for values without a corresponding field; done means the country object use case has a clear supported behavior and regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.