Warning: You are browsing the documentation for PrestaShop 8, 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

Learn how to update to the latest version.

UnitTypeExtension

The UnitTypeExtension used with NumberType or IntegerType represents a number input with unit value (e.g. Kg, Cm & etc.).

Type options

Option Type Default Description
unit string unit Type of unit (e.g. Kg, Cm & etc)

Required Javascript components

None.

Code example

Add NumberType or IntegerType to your form and optionally you can configure unit for it.

<?php

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;

class SomeType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('weight', NumberType::class, [
                'unit' => 'kg',
                'required' => false,
                'empty_data' => '0',
            ])
        ;
    }
}

Preview example

UnitTypeExtension rendered in form