-
Notifications
You must be signed in to change notification settings - Fork 0
TS tn-forms - Form builder #26
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
base: main
Are you sure you want to change the base?
Conversation
- make field to be an instance of FormField
| validate() { | ||
| for (const f of Object.values(this.fields)) { | ||
| if (f instanceof FormField) { | ||
| f.validate() | ||
| } | ||
| } | ||
| return this | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should break out of the builder pattern and instead return a success prop which would tell whether the validation was successful.
If the validation was successful we should also return a data or value where the fully validated form value is returned, so that we can use that type-safely
@oudeismetis From our discussion on bootstrapper
|
Does this resolve the issue with the values allowing for undefined? I was actually thinking we can reduce the number of types that are needed by adding a type to the FormField (and removing the useless one from the Form). From there using some of the typescript type functions to return the value type without undefined IF the field has the required validator otherwise leaving it with it.
|
|
The main issue has always been the static fields. We cannot do any inferring with static types bc they're at class level |
PROTOTYPE
This is an attempt to make this library typesafe.
But at the same time it is likely that we will need to rewrite a part of it.
I'm trying to keep as much as possible the existing code but it is likely that some things might need to change:
form.email.value ?? '')Roadmap
FormFieldand typesafetyvalidateso thatform.valuebecomes the validated value of the form (required fields would show as defined)How would this look in practice
addField