Maybe this is a bad idea, maybe it increases file size way too much or maybe it's simply not technically feasible but.. perhaps you can integrate Joi into this plugin?
Joi is pretty amazing for validation and has a ton of validators already. Looks like size might be a problem but webpack could solve that..
Thoughts?
Nothing prevents you from simply using Joi if you wish to. Vuelidate will accept any function as a validator.
// define a helper for ease of use with vuelidate
const fromJoi = schema => value =>
Joi.validate(value, schema).error === null
// define your object's schema
const schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/)
})
...
// inside Vue component, use as a validation
validations: {
myObject: {
passesSchema: fromJoi(schema)
}
}
You should be able to use it even with async schemas, simply wrapping the callback with promise
// define a helper for ease of use with vuelidate, with support for async validations
const fromJoi = schema => value =>
new Promise(resolve =>
Joi.validate(value, schema, error => resolve(error === null)
)
Ah cool, thanks
Maybe that helper can be added to the vuelidate code? So that a developer can choose to either use Vuelidate validators or the Joi validators.
validations: {
name: Joi.string().required(), // or an array to combine joi and vuelidate validators
email: {
required,
email
}
}
Bad example since both are possible with Vuelidate but Joi has some advanced validators (my original question came from URI scheme checking with Joi).
This is a glue code specific to your usecase. Feel free to use it. I don't want to favour any particular validation function library though, there are really many of those. Also only the internal ones are supporting $params out of the box. For external ones, you still have to use withParams function if you care about that feature.
Vuelidate is ment to be as light as possible, I don't want any dependencies or favour any specific solution. It should allow you to use all of them as easy as possible. It's your choice in your codebase.
Okay. Just wanted to make the suggestion :)
Most helpful comment
This is a glue code specific to your usecase. Feel free to use it. I don't want to favour any particular validation function library though, there are really many of those. Also only the internal ones are supporting
$paramsout of the box. For external ones, you still have to usewithParamsfunction if you care about that feature.Vuelidate is ment to be as light as possible, I don't want any dependencies or favour any specific solution. It should allow you to use all of them as easy as possible. It's your choice in your codebase.