Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.
You might want to read an updated version of this page for the current version, PrestaShop 9. Read the updated version of this page
The TextWithLengthCounterType represents text input with value length counter.
| Option | Type | Default | Description | 
|---|---|---|---|
| max_length | int | None, must be configured | Max length of input value | 
| position | string | before | Configures position for counter. Available options are: beforeandafter | 
| input | string | text | Configured input type textortextarea | 
| Component | Description | 
|---|---|
| admin-dev/themes/new-theme/js/components/form/text-with-length-counter.js | Calculates remaining length for input | 
First, you have to add TextWithLengthCounterType to your form.
<?php
use Symfony\Component\Form\AbstractType;
use PrestaShopBundle\Form\Admin\Type\TextWithLengthCounterType;
class SomeType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('meta_title', TextWithLengthCounterType::class, [
            'max_length' => 255,
        ]);
    }
}
Then in Javascript you have to enable TextWithLengthCounter component.
    import TextWithLengthCounter from "admin-dev/themes/new-theme/js/components/form/text-with-length-counter";
    // enables length counter for all TextWithLengthCounterType inputs on the page
    new TextWithLengthCounter();
