-
Hi! I'm creating an AutoField and noticed that a user can delete a value for a required field, and no error is detected. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @mdesousa. The thing is, that an empty string is a valid string. It's up to you to decide what should the schema check for. I'd suggest one of the following, in the order of my personal preference:
Please note that all of the above require changing your schema. That's not necessarily bad, as one, this can be (semi-)automated, and clearly defines your intention. Also, remember that there's no trimming by default, and you may want to use a custom keyword for that as well. Luckily, |
Beta Was this translation helpful? Give feedback.
Hi @mdesousa. The thing is, that an empty string is a valid string. It's up to you to decide what should the schema check for. I'd suggest one of the following, in the order of my personal preference:
pattern
orformat
to specify the... Well, pattern or format of the string.minLength: N
to specify the minimum input length.isNotEmpty
.Please note that all of the above require changing your schema. That's not necessarily bad, as one, this can be (semi-)automated, and clearly defines your intention.
Also, remember that there's no trimming by default, and you may want to use a custom keyword for that as well. Luckily,
ajv-keywords
got you covered with …