-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP][Form] Add TelType #11360
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
[WIP][Form] Add TelType #11360
Conversation
lepiaf
commented
Jul 9, 2014
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #8026 |
License | MIT |
Doc PR | symfony/symfony-docs#4040 |
'pattern' => '', | ||
'maxlength' => 10, | ||
'autofocus' => '', | ||
'autocomplete' => 'on' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These options don't make sense. Most of them loo like you are tryign to configure HTML attributes (but not working because you don't render them), and Symfony already has a way to configure them through the attr
option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setAllowedValues and setAllowedTypes are useless ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the options you configure here are useless as you never use them
Hi, thx for contributing, What about internationalization ? Maybe a Tel Validator would be great too ? |
Do you mean display phone number in specific format ? Yes It's interesting, but I can't do in this PR. (could I?) |
@L0rD59 Dealing with telephone numbers is hard. My bundle that does this uses a port of libphonenumber which knows a huge range of rules. |
If there is a third party doing it well, I'm all in favor of it. |
Beware that including the proposed telephone validator would add 1,366 new files and 15 MB to the Symfony source code. Don't get me wrong @thewilkybarkid. Your library is great and we really appreciate that you have developed a Symfony bundle. But in my opinion, a full telephone number validator is a very specific need. |
I'm not talking about including this in Symfony, we can just rely on the external lib. |
<input type="tel" | ||
<?php echo $view['form']->block($form, 'widget_attributes') ?> | ||
value="<?php echo $view->escape($value) ?>" | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'tel')) ?>
as for other widgets ?
The bundle from @thewilkybarkid is interesting. @jeremy-derusse I didn't see it. I can change it. |
fix duplicate definition of tel type in twig template
does anyone has more idea for this feature ? or suggestion ? |
@@ -192,6 +192,13 @@ | |||
{{- block('button_widget') -}} | |||
{%- endblock reset_widget %} | |||
|
|||
{% block tel_widget %} | |||
{% spaceless %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaceless were removed in a recent PR (#11386) can you apply changes to the tel_widget ?
* @return mixed The value in the transformed representation | ||
* | ||
* @throws TransformationFailedException When the transformation fails. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use {@inheritdoc}
if your comment doe not improve the interface one
return ''; | ||
} | ||
|
||
return PhoneNumberUtil::getInstance()->format($value, $this->region); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PhoneNumberUtil::format()
expects an object, https://github.com/giggsey/libphonenumber-for-php/blob/master/src/libphonenumber/PhoneNumberUtil.php#L992
You should check if the $value is correct and throw an TransformationFailedException if its not.
Thanks for your feedback, I will improve it. |
@@ -0,0 +1,54 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing license header
https://github.com/misd-service-development/phone-number-bundle/ Already has a phone type for doctrine and a phone type for your form. |
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->addViewTransformer(new PhoneNumberToStringTransformer($options['region'])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a view transformer but a model transformer. The parent type (text
) expects the norm data to be string, so it should be respected in this type
Closing for the reasons explained by @stof, we cannot depend on this library internally. And as there is already a bundle providing such support, that's a better option. |