Skip to content
Source
Sign inSign up
TanStack/form

[Docs] Guide page about getting and setting field values #478

Send to my agent
Closedjuliendelort(GitHub profile, opens in a new tab) opened this issue 3 comments

Something that people usually look for when using a forms library is being able to easily get and set field values, so we should have a page in the guide section for that.

Some topics that the page should cover:

  • How do I initialize the form?
  • How do I initialize the form with values resulting from an API call? (we can show how to do this with and without Tanstack Query)
  • How do I set a single field vs the entire form (if it is possible to set all the fields at once)
  • Will setting a new value programmatically trigger validation? If not, is there a way to trigger it?
  • How do I retrieve the current value of a single field? Of the entire form? (not necessarily within a onchange/onblur callback but also by directly calling the form API object)
  • How do I listen for changes?
  1. I like this idea and outline. Let's move forward with it

  2. crutchcorn(GitHub profile, opens in a new tab) added labelstype: enhancement

  3. crutchcorn(GitHub profile, opens in a new tab) added labelsgood first issue

  4. crutchcorn(GitHub profile, opens in a new tab) added labelstype: docs

  5. I would like to work on this, but is there any specific pattern that I need to follow while writing the docs ?

  6. I'm going to close this issue, as a lot of these questions have been answered. 😄

    Initialise the form

    Initialise the from from async values

    retrieve the current state

    How do I listen for changes

    To set a single value field.setValue({value}) (will trigger validation) form.setFieldValue({field name}, {value}) (will trigger validation unless {dontValidate: true} is provided)

    To set multiple values, you can use form.reset, but that's not it's intended purpose.

Sign in to join this conversation.