1
votes

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

1 Answers

3
votes

Did you try?

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