odolbeau / phone-number-bundle

Integrates libphonenumber into your Symfony application
MIT License
217 stars 43 forks source link

Tel input type not taken into account in twig #153

Open damiensan opened 1 year ago

damiensan commented 1 year ago

Hello,

I don't know if this issue relates to Symfony or to the bundle.

When I use

$builder->add('mobile', PhoneNumberType::class, [
    'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE,

the input rendered by twig is an input type="text" instead of input type="tel"

Do you know how to fix this, did I miss something ?

Thank you

maxhelias commented 1 year ago

Can you publish a reproduce pls ? That way it will be quicker for me to see what's wrong.

damiensan commented 1 year ago

Hello, here it is

Expected Behavior

When I use the PhoneNumberType I want to have a input type="tel" rendered in html not a input type="text"

Current Behavior

The input rendered is a text one.

Steps to Reproduce

  1. Create a Symfony Type
class AddressType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
    { 
    $builder->add('phone', PhoneNumberType::class, [
            'widget'                    => PhoneNumberType::WIDGET_COUNTRY_CHOICE
        ]);
    }
}

Render it in Twig

When I look at the PhoneNumberType, I see

 public function buildView(FormView $view, FormInterface $form, array $options): void
    {
        $view->vars['type'] = 'tel';
        $view->vars['widget'] = $options['widget'];
    }

which seems fine to me.

It seems that the form_layout.div.html.twig does not take this option into account.

Thank you.

damiensan commented 1 year ago

Hello, any news on this ? Regards

Nek- commented 1 year ago

Thank you very much for your issue.

And you're right! It could be better. Not that easy though.

We need to:

  1. Bring the ability to use the tel type with an option.
  2. Trigger a deprecation when the option is not specified.
  3. Plan a change in the next major version on this specific field because it should be the default!

You can make a PR for this change if you want.