Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 in form number field #174

Open
kricha opened this issue Mar 12, 2018 · 3 comments
Open

0 in form number field #174

kricha opened this issue Mar 12, 2018 · 3 comments

Comments

@kricha
Copy link

kricha commented Mar 12, 2018

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
Copy link
Author

kricha commented Mar 22, 2018

@thewilkybarkid @rh389

@osavchenko
Copy link

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

@kricha
Copy link
Author

kricha commented Jun 17, 2018

@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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants