Skip to content

Character count limit for title field #11732

Discussion options

You must be logged in to vote

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

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants