I’m doing my first steps with the blueprints and I tryed out that:
title:
label: Title
type: text
validate:
max: 21
If I enter on the kirbiy panel page in the field Title (or my custom text field) a text with 21 characters or less everything works fine. When I enter only digits like 12345 I get the message that I cant save this page.
I know a title consisting only out of digits is very unlikely but who knows.
Hi @sandbox
If you want to validate the maximum length of a text field you have two options:
max = number of characters or value if only numeric characters.
maxwords = number of words
Thank you for the explanation but unfortunately doesn’t seems correct.
If I use max: 21 then I can see a counter in the upper right corner above the text field. And if I use size: 21 I get no counter and the same error (Can’t save the page.) when I enter only digits.
Ah I found it!
The size() function used in max() checks if the value is numeric and in this case returns its value instead of its length.
I think it’s safe to say this is by design. I’ll let the support crew confirm.
Note: If a title is mix characters, you’re safe with max!
I’mm editing my first post given that I was completely wrong and don’t want to mislead people
I had already figured it out, that if I add any other character than a digit then it works. It’s a rare case but if you want a titel or in my case a menu item with only digits then you run into it.
If you want to validate a number, you should use a number field. IMHO, a text field is a string, so it should check string length. Although we might need another validator.
Alright! I love digging into the code to understand what causes the issue like that. Mostly because the Kirby code is easy to read. I would never have done that with another CMS… Thanks for walking along
The current max validator is used for both text and number fields, it is field type agnostic. Therefore, we need a new validator for strings only. CamelCase is for readability.