Issue
I was curious if Appsmith supports JOI validation since it is widely used by our clients. Unfortunately, Appsmith does not support JOI out of the box, but a new feature is coming soon that will allow for the importation of JS libs, such as JOI, making validation easier with an external library.
Resolution
The solution to validating JOI in Appsmith is to import JS libs (npm packages) using a new feature that will soon be introduced. This will make it easier to use external libraries for JOI validation.
Here's an example of importing the JOI library in Appsmith:
- In the widget where you want to use JOI validation, click on "Edit JS" in the "Custom JS" section.
- Add the following code to import the JOI library:
import joi from 'joi';
// example validation
const schema = joi.object({
name: joi.string().alphanum().min(3).max(30).required(),
email: joi.string().email().required(),
age: joi.number().integer().min(18).max(120).required(),
});
const result = schema.validate({
name: 'John Doe',
email: 'johndoe@example.com',
age: 30,
});
console.log(result);
- Modify the schema and data as per your validation needs.
- Save the widget and you're done!
With this, you can now use JOI validation in your Appsmith app.