Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
How to trigger form validations on submit
Post Flair (click to view more posts with a particular flair)
Post Body

Hey guys. Sounds like a super common question right. However, there is something unique in my situation. The form fields are completely dynamic (think JSON structure with various form fields with various attributes etc. being fed into the app on start and then creating a bunch of divs with dynamic, varying form fields. There are an arbitrary amount of pages with these form fields that the user has to continue through.

I am using Redux. My question is what is the cleanest way to trigger, for example, all field validations on the current page when the user clicks the "continue" button to get to the next page of forms?

For example, if there are 5 fields rendered onto the page, 3 of which are required, if the user clicks continue without touching any of the fields, what would be the cleanest workflow to highlight the 3 required fields in red and show the error text under the fields?

I will add some thoughts I have because I don't want it to seek like I have stumbled over this process for awhile now.

  1. On page load, store an array or arrays in redux designated to maintaining the errors for each of the fields. Each nested array is a page, each page can have multiple objects holding the field identifier as a key and the value as another array if errors. On app load, build the whole array structure in redux. On continue button click, iterate through the fields on the page that are required, place those errors in the corresponding arrays. I'm lost now, see why I don't like this.

  2. Pass a handler down to the continue button on click that sets a boolean in a higher component that passes that boolean down to all the field components. On field component render, if the boolean is true, trigger a validation on the field. No redux use here..

Any advice is greatly appreciated. I'm coming from Vue, where I would use Vuelidate to get stuff done. Plus this use case is very unique, since it is such a unique form compilation situation. Thank you very much in advance for tips.

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
22,030
Link Karma
800
Comment Karma
21,157
Profile updated: 1 day ago
Posts updated: 9 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago