Skip to content

Form Validation of IntegerType is rounding bigint with no warning #30582

Closed
@AdelBachene

Description

@AdelBachene

Symfony version(s) affected: 4.x.x

Description
Whenever we try to validate a bigint with IntegerType the number will be rounded with no warning

How to reproduce

  1. In your entity add a field of type bigint
  /**
     * @ORM\Column(name="original_transaction_id", type="bigint", nullable=true)
     */
    private $originalTransactionId;
  1. define Form validation type:
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;

class CreateFormValidationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add("originalTransactionId", IntegerType::class, [
                "required" => true,
                "constraints" => [
                    new Assert\NotNull,
                ]
            ])
     }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            "csrf_protection" => false,
            "data_class" => MyEntity::class,
        ]);
    }
}
  1. While validating the field it will change the value from bigint to a rounded int
            $receiptFormType = CreateFormValidationType::class;
            $receiptForm = $this->formFactory->create($receiptFormType, $MyEntity, ['allow_extra_fields' => true]);
            $receiptForm->submit($data, true);

Additional context
I'm using this version of symfony form "symfony/form": "^4.2"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions