Character count limit for title field #11732
Answered
by
brandonkelly
TheFunkyMonk
asked this question in
Ideas
-
I have a situation where we'd like to limit the character count for an entry's title field, like you can with custom plain text fields. Possible to add to the field preview window in the layout designer, maybe under an "Advanced" toggle if we want to keep the interface clean? |
Beta Was this translation helpful? Give feedback.
Answered by
brandonkelly
Aug 4, 2022
Replies: 1 comment
-
We can definitely consider this down the road. For now, you can enforce it by registering a custom validation rule from a module: use craft\elements\Entry;
use craft\events\DefineRulesEvent;
use yii\base\Event;
Event::on(
Entry::class,
Entry::EVENT_DEFINE_RULES,
function(DefineRulesEvent $event) {
/** @var Entry $entry */
$entry = $event->sender;
if ($entry->section->handle === 'mySectionHandle') {
$event->rules[] = ['title', 'string', 'max' => 50];
}
}
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
brandonkelly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can definitely consider this down the road. For now, you can enforce it by registering a custom validation rule from a module: