ml-archive / forms

Tools for working with Forms in Vapor
MIT License
7 stars 0 forks source link

Make optional validator return the key that is nil #15

Open steffendsommer opened 6 years ago

steffendsommer commented 6 years ago

Make the optional validator return a validation error and make it specify what field was (unexpectedly) nil.

siemensikkema commented 6 years ago

I think this should be handled for all validation errors, not just those from the OptionalValidator.

How about something like this:

FormField(validator: MyValidator().prefixingErrors(with: “Error validating value for ‘\(myKey)’: ”))

or

MyValidator().indicateThatErrorsAreForKey(for: myKey)

I'd like to find a better name. Any ideas @steffendsommer ?

steffendsommer commented 6 years ago

I agree that it would be nice to have this for all validators. Would it make sense to have this responsibility on the FormField since it has the key already (or maybe that's optional?)?

siemensikkema commented 6 years ago

You're right. That could be done. I even thought of that and forgot it again ... ("yeah yeah, of course you did")