question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any way to only submit values that are present in the form?

See original GitHub issue

Question/Feature

I have a redux store that keeps a couple of hundred settings. Of those I only want to display 10-20 in the form. No problem so far. But when I submit the form, all values are submitted, not only those present in the form (the values with an input field).

I suppose I could pick just the values I need from the store state in mapPropsToValues, but it seems like duplicated work.

Is there any better way to handle this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
klis87commented, Mar 15, 2018

@jomag If you wanna limit fields, you can use yup for this. I do it for highly dynamic forms, using when like @latviancoder mentioned, but also somehow I abuse yup.validate with stripUnknown: true - https://github.com/jquense/yup#mixedvalidatevalue-any-options-object-promiseany-validationerror

Another trick I use is const initialValues = schema.cast(), which can give me default values of a schema.

My point is, for me yup is a logic/validation layer, Formik is a view layer, each one has its own responsibility.

1reaction
jaredpalmercommented, Apr 18, 2018

Seems like this has been resolved. Would be great to add it to docs section on validation. @klis87 May hit you up on Twitter about your technique so I can add as a docs example

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get all a form's values that would be submitted ...
Get the data from the form by using FormData objects. var formData = new FormData(formEl);. Get the value of the fields by the...
Read more >
<input type="submit"> - HTML: HyperText Markup Language
A string indicating the HTTP method to use when submitting the form's data; this value overrides any method attribute given on the owning...
Read more >
How to add Hidden Fields to your Google Form - YouTube
Using hidden fields is a great way to set default values within a form submission to make it easier for you to organize...
Read more >
Show form questions based on answers - Google Support
Go to section based on answer. Next to each answer, click the Down arrow "" to choose where to send people.
Read more >
.submit() | jQuery API Documentation
The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found