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

The UrlType renders an <input type = "text" /> instead of an <input type = "url" /> #30635

Closed
iraldoad opened this issue Mar 22, 2019 · 13 comments

Comments

@iraldoad
Copy link

Symfony version(s) affected: 3.4.22

Description
The Url Type renders an instead of an so this field is not validated in Google Chrome.

@xabbuh
Copy link
Member

xabbuh commented Mar 22, 2019

Which Symfony version do you use? How is your form configured?

@ro0NL
Copy link
Contributor

ro0NL commented Mar 22, 2019

Related to #29926?

@iraldoad
Copy link
Author

Hi. Sorry for the delay when responding. This is the field:

$builder->add('url', UrlType::class, [
                'default_protocol' => 'https',
                'required' => false,
                'attr' => [
                    'class' => 'form-control',
                    'placeholder' => 'https://domain.com',
                    'pattern' => '^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$'
                ]
            ])

As you can see I had to add a pattern to validate the url. This is the HTML:

<input type="text" name="entity[url]" class="form-control" placeholder="https://domain.com" pattern="^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$" inputmode="url">

@iraldoad
Copy link
Author

Anotación 2019-03-23 223230

@ro0NL
Copy link
Contributor

ro0NL commented Mar 24, 2019

#29926 is released in 3.4.22, looks like you received a bugfix 😅

(because of default_protocol the input should allow for protocol-less values, hence type text in this case)

@xabbuh
Copy link
Member

xabbuh commented Mar 24, 2019

As @ro0NL explained this is the expected behaviour. So I'm going to close here. Thank you for understanding.

@xabbuh xabbuh closed this as completed Mar 24, 2019
@iraldoad
Copy link
Author

As I understand, if I remove the default protocol option should I render the input to url type?

@xabbuh
Copy link
Member

xabbuh commented Mar 24, 2019

If you remove the option, the type will be rendered as a url input type.

Edit: The option needs to be set to null explicitly as its default value is http.

@iraldoad
Copy link
Author

Well no, it continues to be rendered in the same way.

@xabbuh
Copy link
Member

xabbuh commented Mar 24, 2019

Can you create a example application that allows to reproduce your problem?

@iraldoad
Copy link
Author

I have created a project but I have not been able to prove it. Use the crud generator and do not open the form page. Initially he sent me the following error "Maximum function nesting level of '256' reached, aborting! stackoverflow". Afterwards no longer.
This is the link: https://github.com/iraldoad/my_project.git

@xabbuh
Copy link
Member

xabbuh commented Mar 25, 2019

When adding the url type in the buildForm() method of your custom UrlType, you do not reference theUrlType from the Form component, but again add your own UrlType which creates a recursion (see https://github.com/iraldoad/my_project/pull/1). And then you need to explicitly set default_protocol to null as its default value is http (I have corrected by comment above):

$builder->add('url', CoreUrlType::class, ['default_protocol' => null]);

@iraldoad
Copy link
Author

Great. Ok thanks.

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

No branches or pull requests

4 participants