adonisjs / validator

Schema based validator for AdonisJS
MIT License
115 stars 40 forks source link

how to manipulate a field from adonis validator? #173

Closed paragrudani1 closed 1 year ago

paragrudani1 commented 1 year ago

Let's say I want to slice a string from a validator.

There are lot of use cases where one needs to manipulate value using custom validation rule.

if I can create a custom rule with feature of manipulate values, I do not have to create little utility functions around the app also It's very difficult to manipulate fields manually in a complex object.

Here's something I need after creating custom rule of trim: ex: rules.slice(20)

thetutlage commented 1 year ago

Please reference the trim rule. It uses the mutate function to mutate the value of a field.

https://github.com/adonisjs/validator/blob/develop/src/Validations/string/trim.ts#L27-L32

paragrudani1 commented 1 year ago

Thanks for guiding me @thetutlage ! I have just tried, and it works like a magic.