Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text.validation.length.max error message not working properly in adminUI #7334

Open
pkuwyn opened this issue Mar 6, 2022 · 13 comments
Open

Comments

@pkuwyn
Copy link

pkuwyn commented Mar 6, 2022

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.

chrome-capture

@emmatown
Copy link
Member

Could you make sure that you haven't set max to 3? We're unable to reproduce this problem

@pkuwyn
Copy link
Author

pkuwyn commented Mar 17, 2022

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".

@pkuwyn
Copy link
Author

pkuwyn commented Mar 17, 2022

chrome-capture
Maybe this Gif helps!

@dcousens
Copy link
Member

@pkuwyn can you please paste your exact configuration? We can't reproduce this with the instructions provided 😕

@pkuwyn
Copy link
Author

pkuwyn commented Mar 17, 2022

@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.

@dcousens
Copy link
Member

@pkuwyn could you please copy paste - as text - your problematic Keystone schema?

@pkuwyn
Copy link
Author

pkuwyn commented Mar 18, 2022

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 }),
    },
  }),
};

@gnadenthal
Copy link

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,
          },
        },
      }),

CleanShot 2022-03-30 at 21 23 10

@MohammadKurjieh
Copy link
Contributor

Any updates on this? I am getting the same error as @gnadenthal. #7334 (comment)

@MohammadKurjieh
Copy link
Contributor

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 👍🏻

@dcousens
Copy link
Member

dcousens commented May 12, 2022

@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?

@MohammadKurjieh
Copy link
Contributor

@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...

@dcousens
Copy link
Member

@MohammadKurjieh the decimal validation error was fixed in #7417, and it shouldn't have any effect on a text field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants