phone-number-bundle icon indicating copy to clipboard operation
phone-number-bundle copied to clipboard

0 in form number field

Open kricha opened this issue 6 years ago • 3 comments

I have a problem with form rendering of entity with already defined data. For example in database is entity with phone field +380509882331, but in form i've got (zero in start of number must be a part of country code)screen shot 2018-03-13 at 12 04 28 am

kricha avatar Mar 12 '18 22:03 kricha

@thewilkybarkid @rh389

kricha avatar Mar 22 '18 13:03 kricha

Could you provide code from your entity and form type, please?

osavchenko avatar Jun 05 '18 06:06 osavchenko

@osavchenko yes.

Form:

            ->add('phone', PhoneNumberType::class, [
                'widget'          => PhoneNumberType::WIDGET_COUNTRY_CHOICE,
                'country_choices' => ['UA'],
                'attr'            => [
                    'class' => 'input-group',
                ],
                'constraints' => [
                    new PhoneValidator(),
                ],
                'country_placeholder' => 'form.join.country_placeholder',
            ])

Entity:

    /**
     * @var PhoneNumber
     * @ORM\Column(type="phone_number", unique=true)
     * @Type("libphonenumber\PhoneNumber")
     */
    private $phone;
    /**
     * @return PhoneNumber
     */
    public function getPhone()
    {
        return $this->phone;
    }
    /**
     * @param $rawPhone
     *
     * @throws \libphonenumber\NumberParseException
     *
     * @return User
     */
    public function setRawPhone(string $rawPhone): self
    {
        $phoneNumber = PhoneNumberUtil::getInstance()->parse($rawPhone);
        $this->phone = $phoneNumber;
        return $this;
    }
    /**
     * @param PhoneNumber $phone
     */
    public function setPhone(PhoneNumber $phone): self
    {
        $this->phone = $phone;
        return $this;
    }

kricha avatar Jun 17 '18 09:06 kricha