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

Tel input type not taken into account in twig

Open damiensan opened this issue 9 months ago • 4 comments

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

damiensan avatar Sep 28 '23 08:09 damiensan

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

maxhelias avatar Oct 14 '23 21:10 maxhelias

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 avatar Oct 24 '23 15:10 damiensan

Hello, any news on this ? Regards

damiensan avatar Nov 15 '23 08:11 damiensan

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.

Nek- avatar Nov 16 '23 13:11 Nek-