Javalin: Using validator without exception

Created on 20 May 2020  路  5Comments  路  Source: tipsy/javalin

Describe the feature
when a form contains several fields, it is irritating to have only one error at a time when the whole form is wrong. It would be interesting to have the possibility to check the validity of fields, without the need for an exception, for example by adding an isValid method that only returns a boolean.

By exemple, in case of a subscription form, user can't give bad data for email, firstname, lastname, email, birthdate. The user should see all errors at the same time and not discover them one after the other.

Adding a new method without exception (ex: isValid: boolean) allow developer to check all fields before returning a response

Thanks

FEATURE REQUEST

Most helpful comment

Validations are currently chainable to add many rules. I think it'd be cool if instead of having a isValid it had a collect failures that returned a list of messages from failed validations, as wouldn't be able to use the chaining functionality even with isValid if you are trying to give all potential errors back to a user for a specific field.

In the case of a body it gets a little more complicated as you can perform many checks on many different properties, and it'd be nice to be able to validate the entire object and get all errors back from it (preferably with labels for the messages so you can stick the correct error message back on the correct form field).

I'd be happy to help with implementing either/both of these. Or if we just want isValid and you need any help @thibaultmeyer I'd be happy to help with that too.

All 5 comments

Good idea @thibaultmeyer, thanks! Would you like to submit at PR ?

Hello,

i can try.

Validations are currently chainable to add many rules. I think it'd be cool if instead of having a isValid it had a collect failures that returned a list of messages from failed validations, as wouldn't be able to use the chaining functionality even with isValid if you are trying to give all potential errors back to a user for a specific field.

In the case of a body it gets a little more complicated as you can perform many checks on many different properties, and it'd be nice to be able to validate the entire object and get all errors back from it (preferably with labels for the messages so you can stick the correct error message back on the correct form field).

I'd be happy to help with implementing either/both of these. Or if we just want isValid and you need any help @thibaultmeyer I'd be happy to help with that too.

@MrThreepwood @cwildfoerster https://github.com/tipsy/javalin/pull/976 has been merged.

I'll close this issue now, please re-open if there are any concerns.

Was this page helpful?
0 / 5 - 0 ratings