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

Should we have setValues method? #49

Closed
hnq90 opened this issue Mar 22, 2017 · 3 comments
Closed

Should we have setValues method? #49

hnq90 opened this issue Mar 22, 2017 · 3 comments

Comments

@hnq90
Copy link
Contributor

hnq90 commented Mar 22, 2017

If we want to set value to multiple fields at once, we have to use setValues.

Example:

setValue('field1', value1)
setValue('field2', value1)
setValue('field3', value1)
setValue('field4', value1)
...
setValue('field99', value1)

Use setAllValues will set/replace all form values but it makes other attributes which are not in setAllValues arguments is undefined.

We can create an object which merges values from form's value with new values as:

<Form>
  {({values, setAllValues}) => {
    const profile = {
      name: 'Tanner Linsley',
      job: 'Software Developer',
      age: 27
    }
   const newValues = Object.assign({}, values, profile)
    return (
      <button onClick={() => setAllValues(newValues)}
  }}
</Form>

IMHO, it's better to have a new method setValues or setMultipleValues which doesn't override others fields' value.

Please let me know your opinion.

@SeeThruHead
Copy link
Contributor

Please correct me if I'm wrong but if you always have values passed down when you get setAllValues can this not be implemented 100% in userland? ie by wrapping setValues

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Mar 22, 2017 via email

@hnq90
Copy link
Contributor Author

hnq90 commented Mar 23, 2017

Thanks, that's which I used.

@hnq90 hnq90 closed this as completed Mar 23, 2017
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

No branches or pull requests

3 participants