"string.email>0" custom message not working

Hey for most types i use .configure({message: "Some error message"}) to customize error messages for fields. When i use it on email type it seems configure does not work the same:
const stringEmail = type("string.email>0")
.configure({message: "You need to fill in your email"})

stringEmail.from("")

// error: email ("") must be... ◦ an email address ◦ non-empty
const stringEmail = type("string.email>0")
.configure({message: "You need to fill in your email"})

stringEmail.from("")

// error: email ("") must be... ◦ an email address ◦ non-empty
What should I do to get a custom message in this case?
1 Reply
Claus
Claus7d ago
configure only works with scopes:
configure({
required: {
message: (ctx) => `The field ${ctx.path} is required`,
},
});

const $ = type.scope({});

const schema = $.type({
name: "string",
});
configure({
required: {
message: (ctx) => `The field ${ctx.path} is required`,
},
});

const $ = type.scope({});

const schema = $.type({
name: "string",
});

Did you find this page helpful?