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

Tel input type not taken into account in twig #153

Open
damiensan opened this issue Sep 28, 2023 · 8 comments · May be fixed by #182
Open

Tel input type not taken into account in twig #153

damiensan opened this issue Sep 28, 2023 · 8 comments · May be fixed by #182
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@damiensan
Copy link

damiensan commented Sep 28, 2023

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

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

@maxhelias maxhelias added the support Support requested label Oct 14, 2023
@damiensan
Copy link
Author

damiensan commented Oct 24, 2023

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

Hello, any news on this ?
Regards

@Nek-
Copy link
Collaborator

Nek- commented Nov 16, 2023

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.

@maxhelias maxhelias added enhancement New feature or request good first issue Good for newcomers and removed support Support requested labels Sep 1, 2024
@abdellahrk abdellahrk linked a pull request Dec 12, 2024 that will close this issue
@abdellahrk
Copy link

Can you throw more light on these following points? I just sent a PR maybe I can update it.

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!

@odolbeau
Copy link
Owner

According to the latest available form_div_layout.html.twig, this option looks correctly handled by symfony.

Could you provide more details regarding versions you're using? Maybe a reproducer project with minimal dependencies?

@mrcmorales
Copy link

hi @odolbeau

May be the problem is that the form type is TextType and not TelType ?

@see https://github.com/odolbeau/phone-number-bundle/blob/master/src/Form/Type/PhoneNumberType.php#L111

@odolbeau
Copy link
Owner

odolbeau commented Jan 4, 2025

@mrcmorales You're right, I was looking for the single_text widget! 👍
@abdellahrk provided PR #182 to fix this issue but when need to correctly handle the "kind of" BC Break it could introduce (see PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants