1

It seems like joi browser does not allow to have empty string. This is my schema:

schema = {
    _id: Joi.string(),
    heading: Joi.string()
      .min(5)
      .max(50)
      .label("Heading")
      .required(),
    subHeading: Joi.string().max(50)
  };

If I leave the subHeading field empty (because it is not a required field) I get an error: ""subHeading" is not allowed to be empty"

Is there anyways to allow empty string in the validation?

I'm using Node.js for the backend and my model looks like this:

const headingSchema = new mongoose.Schema({
  heading: {
    type: String,
    minlength: 5,
    maxlength: 50,
    required: true
  },
  subHeading: {
    type: String,
    minlength: 5,
    maxlength: 50
  }
});

So when I use Postman and send a put request I can leave the subHeading field empty. So this is a problem with joi-browser.

1 Answer 1

3

Did you try?

schema = {
    _id: Joi.string(),
    heading: Joi.string()
      .min(5)
      .max(50)
      .label("Heading")
      .required(),
    subHeading: Joi.string().max(50).allow('')
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.