misd-service-development / phone-number-bundle

Integrates libphonenumber into your Symfony2-Symfony4 application
459 stars 143 forks source link

Could not convert database value "0752086455" to Doctrine Type phone_number #232

Open MiguelAdige opened 3 months ago

MiguelAdige commented 3 months ago

Hello after installing the perfect bundle for the task I want to do. I get this error. Could not convert database value "" to Doctrine Type phone_number I searched a bit and came across this discussion: https://github.com/misd-service-development/phone-number-bundle/issues/58 But this didn't solve my problem, can you help me? thank

doctrine:
  dbal:
    types:
      phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType

in builder form :

use libphonenumber\PhoneNumberFormat;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
................................................................................................

->add('phone', PhoneNumberType::class, [
                'format' => PhoneNumberFormat::INTERNATIONAL,
                'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE,
                'country_display_emoji_flag' => true,
                'country_placeholder' => $this->translate->trans('Choisisez l\'indicatif', domain: 'security'),
                'label' => $this->translate->trans("Téléphone portable", domain: 'security'),
                'row_attr' => ['class' => 'input-group mb-3'],
                'country_options' => [
                    'autocomplete' => true,
                ],
            ]);

twig :

       {{ form_start(form) }}
       {{ form_row(form.firstname) }}
       {{ form_row(form.lastname) }}
       {{ form_row(form.phone) }}
        <button class="btn btn-primary w-100 py-2" type="submit">{% trans %}Sauvegarder{% endtrans %}</button>
       {{ form_end(form) }}

entity :

#[PhoneNumber(regionPath: 'countryPhone', format: PhoneNumberFormat::INTERNATIONAL, type: PhoneNumber::MOBILE)]
#[ORM\Column(length: 35, nullable: true, type: PhoneNumberType::NAME)]
private ?string $phone = null;