TextWithRecommendedLengthType

It is used to add a field with a recommended input length counter to the form.

Type options

Option Type Default value Description
recommended_length int

Required Javascript components

Component Description
TextWithRecommendedLengthCounter Adds a recommended length counter to the input

Code example

$builder->add('meta_description', TranslatableType::class, [
    'label' => $this->trans('Meta description', 'Admin.Global'),
    'type' => TextWithRecommendedLengthType::class,
    'help' => $invalidCharsText,
    'required' => false,
    'options' => [
        'recommended_length' => self::RECOMMENDED_DESCRIPTION_LENGTH,
        'attr' => [
            'maxlength' => self::META_DESCRIPTION_MAX_CHARS,
        ],
        'constraints' => [
            new TypedRegex([
                'type' => 'generic_name',
            ]),
            new Length([
                'max' => self::META_DESCRIPTION_MAX_CHARS,
                'maxMessage' => $this->trans(
                    'This field cannot be longer than %limit% characters',
                    'Admin.Notifications.Error',
                    ['%limit%' => self::META_DESCRIPTION_MAX_CHARS]
                ),
            ]),
        ],
    ],
])

Preview example

TextWithRecommendedLengthType rendered in form