keystone
keystone copied to clipboard
text.validation.length.max error message not working properly in adminUI
1: npm init keystone-app 2: add code to a text field and run dev server
fields: {
name: text({
validation: {
length: {
max: 8, //this max property caused the bug
min: 3,
},
},
}),
3: go to adminUI and try to input a name longer then 8 character.
the error message show :Name must be no longer than 3 characters , the error message uses the min property for the max validation error.

Could you make sure that you haven't set max to 3? We're unable to reproduce this problem
I set min to 3, max to 8. The validtaion logic is right, only if your input string is longer than 8, the red error message will show up. however the error message itsself is incorrect, it showed "Name must be no longer than 3 characters", which should be "must be no longer than 8 characters".
Maybe this Gif helps!
@pkuwyn can you please paste your exact configuration? We can't reproduce this with the instructions provided :confused:
@pkuwyn can you please paste your exact configuration? We can't reproduce this with the instructions provided 😕 reproduce.zip Use this, just npm install and npm run dev; try input a string longer than 8 at the User.name field in the admin UI.
@pkuwyn could you please copy paste - as text - your problematic Keystone schema?
import { list } from "@keystone-6/core";
import {
text,
relationship,
password,
timestamp,
select,
} from "@keystone-6/core/fields";
import { document } from "@keystone-6/fields-document";
import { Lists } from ".keystone/types";
export const lists: Lists = {
User: list({
fields: {
name: text({
validation: {
isRequired: true,
length: {
max: 8,
min: 3,
},
},
}),
email: text({
validation: { isRequired: true },
isIndexed: "unique",
isFilterable: true,
}),
password: password({ validation: { isRequired: true } }),
posts: relationship({ ref: "Post.author", many: true }),
},
ui: {
listView: {
initialColumns: ["name", "posts"],
},
},
}),
Post: list({
fields: {
title: text(),
status: select({
options: [
{ label: "Published", value: "published" },
{ label: "Draft", value: "draft" },
],
defaultValue: "draft",
ui: {
displayMode: "segmented-control",
},
}),
content: document({
formatting: true,
layouts: [
[1, 1],
[1, 1, 1],
[2, 1],
[1, 2],
[1, 2, 1],
],
links: true,
dividers: true,
}),
publishDate: timestamp(),
author: relationship({
ref: "User.posts",
ui: {
displayMode: "cards",
cardFields: ["name", "email"],
inlineEdit: { fields: ["name", "email"] },
linkToItem: true,
inlineCreate: { fields: ["name", "email"] },
},
}),
tags: relationship({
ref: "Tag.posts",
ui: {
displayMode: "cards",
cardFields: ["name"],
inlineEdit: { fields: ["name"] },
linkToItem: true,
inlineConnect: true,
inlineCreate: { fields: ["name"] },
},
many: true,
}),
},
}),
Tag: list({
ui: {
isHidden: true,
},
fields: {
name: text(),
posts: relationship({ ref: "Post.tags", many: true }),
},
}),
};
I am getting related (but different) error when only validation.length.max is set. The error is using null as invalid length. The configured field is:
model: text({
label: "Model",
validation: {
length: {
max: 19,
},
},
}),

Any updates on this? I am getting the same error as @gnadenthal. https://github.com/keystonejs/keystone/issues/7334#issuecomment-1084007413
After some tinkering around, we found that setting any value to the min would fix this issue.
Incase you don't want to have a minimum required length, you can set it to be 0 and it will still work fine 👍🏻
@pkuwyn I can't reproduce this, I used your posted schema to no avail.
@MohammadKurjieh if you can reproduce this, could you provide a repository that we could test on? I can't reproduce the example from @gnadenthal either.
What browser? What node version?
@dcousens the issue is fixed now. The weird part was that I wasn't able to reproduce on my local machine only on the deployment server. I was running the same versions of node-npm-....
We cleared the npm caches removed the node_modules and updated keystone to the latest release (12 May 2022). We think this issue is resolved by this update link
Note: the update didn't take place until we cleared everything...
@MohammadKurjieh the decimal validation error was fixed in https://github.com/keystonejs/keystone/pull/7417, and it shouldn't have any effect on a text field.