Comments (22)
it works form me
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
class CustomPhoneNumberType extends PhoneNumberType
{
public function getBlockPrefix()
{
return 'custom_tel';
}
}
and add widget YourBundle:Form:custom_tel_widget.html.twig:
{% block custom_tel_widget -%}
{% if widget is constant('Misd\\PhoneNumberBundle\\Form\\Type\\PhoneNumberType::WIDGET_COUNTRY_CHOICE') %}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
<div {{ block('widget_container_attributes') }}>
{{- form_widget(form.country) -}}
{{- form_widget(form.number) -}}
</div>
{% else -%}
{{- block('form_widget_simple') -}}
{%- endif %}
{%- endblock custom_tel_widget %}
config.yml
twig:
...
form_themes:
- ..
- 'YourBundle:Form:custom_tel_widget.html.twig'
from phone-number-bundle.
Hey, @thewilkybarkid
Same error for me after symfony upgrade 3.2 => 3.4
Now i'am using symfony 3.4 with Twig bridge 3.4
And the new 'form_div_layout.html.twig' template use 'tel_widget' block name. So i think a new name for the misd "tel_widget" is needed !
When remove 'tel_block' in the vendor file everything is ok !
from phone-number-bundle.
I sincerely apologize @thewilkybarkid . The issue is not with your bundle but my mistake. It seems that the HTML5 type 'tel' styling from another part of my code was affecting your component rendering. Both had the same block name ("tel_widget"). So instead of rendering your control using your template, it was using this template. And since that HTML5 template was a simple textbox, it was hitting the error.
Once again, I apologize for the trouble and appreciate your good work. Keep it up and I look forward to more development work from you that will help people like me.
from phone-number-bundle.
If you don't mind me suggesting, it would be better to rename the name of the type and use that in the twig instead of 'tel'. Reason being that 'tel' is a common name and it may conflict again when other template also uses the same name.
from phone-number-bundle.
no one is fixing this lol — This lib should not be used in prod anymore.
from phone-number-bundle.
@numediaweb @chokrijobs no need to do so as this PR #175 should have fixed the issue. Could you confirm it to me ?
from phone-number-bundle.
@JusteLeblanc it works
from phone-number-bundle.
@chokrijobs thanks you for your solution ;-)
from phone-number-bundle.
Re 1, this is a change between Symfony 2 and 3, the doc needs updating.
Re 2, I've just created a fresh Symfony standard-edition project, added a simple form with those fields and it works... What version of Symfony and the bundle are you using? Can you provide some more details where the array to string conversion is happening? (eg file/line number, what value etc)
from phone-number-bundle.
Regarding 2nd,
Symfony version: "3.0.*"
Phone-Number-Bundle version: "1.1.x-dev"
Entity Class Attribute
/**
* @var \libphonenumber\PhoneNumber
*
* @AssertPhoneNumber(type="FIXED_LINE")
*
* @Type("libphonenumber\PhoneNumber")
*
* @ORM\Column(name="landline_no", type="phone_number", nullable=true)
*/
private $landlineNo;
Class Type Form
->add('landlineNo', PhoneNumberType::class, array('widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE))
Error Message
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion") in form_div_layout.html.twig at line 13.
I don't understand the error since I am not setting any values and it is a fresh form (new account I am trying to create). From what I can tell, when I add the WIDGET_COUNTRY_CHOICE option, it is throwing an error. Without it, it works fine.
->add('landlineNo', PhoneNumberType::class, array('default_region' => 'GB'))
So only conclusion I came to was that this country choice was what was throwing the error. I didn't do any customization to the Type or Form.
from phone-number-bundle.
To clarify, the error is happening on:
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
isn't it?
Could you debug what those values are? (ie which one is an array, and which one is it, and ideally where is it coming from)
from phone-number-bundle.
The ContextErrorException shows different code.
echo " ";
if ( !twig_test_empty((isset($context["value"]) ? $context["value"] : $this->getContext($context, "value")))) {
echo "value=\"";
echo twig_escape_filter($this->env, (isset($context["value"]) ? $context["value"] : $this->getContext($context, "value")), "html", null, true);
echo "\" ";
}
echo "/>";
The yellow highlighted line is from
echo twig_escape_filter($this->env, (isset($context["value"]) ? $context["value"] : $this->getContext($context, "value")), "html", null, true);
from phone-number-bundle.
That's compiled Twig. It shows the problem is with the value
of whichever field that is (I'm assuming it's the number field). Can you debug to find out what the value is?
from phone-number-bundle.
I am not setting a value. It is an empty value for that field since it is a new entry.
Would a full stacktrace help you? I am at a loss on how to debug this because the Type gets rendered in twig and I don't know how to debug that.
If not, kindly guide me on how to debug this.
PS: I have attached the stacktrace for the error incase you want it.
from phone-number-bundle.
No problem @prindacerk, glad you were able to solve it!
from phone-number-bundle.
You can use this solution in your twig template.
{% block content %}
{% form_theme form with ['MisdPhoneNumberBundle:Form:tel_bootstrap.html.twig'] %}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
{% endblock %}
from phone-number-bundle.
This doesn't work in symfony4
{% block content %}
{% form_theme form with ['MisdPhoneNumberBundle:Form:tel_bootstrap.html.twig'] %}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
{% endblock %}
from phone-number-bundle.
I have the same issue when upgrading to Symfony 3.4 version.
We are using SonataAdminBundle, and I can't fix the issue for our admin pages.
@thewilkybarkid do you plan to change the widget name so that we can use the lib with Symfony 3.4 form_div_layout ?
Many thanks
from phone-number-bundle.
Same here with Symfony 3.4 and EasyAdminBundle.
from phone-number-bundle.
@chokrijobs solution worked for me. Thanks!
from phone-number-bundle.
@numediaweb thank you too
from phone-number-bundle.
@1988gadocansey for symfony 4 you can use
{% form_theme form '@MisdPhoneNumber/Form/tel_bootstrap.html.twig' %}
from phone-number-bundle.
Related Issues (20)
- Exception on form rendering when using Synfony 4 build-in Bootstrap 4 form support HOT 3
- PhoneNumberType is overriding template for Symfony TelType HOT 1
- Extensions Are Silently Dropped HOT 4
- Missing phone_number_parse Twig filter
- JMS Serializer: return empty phoneNumber: [] HOT 3
- Support `default_region` for `PhoneNumberType` with option `'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE`
- Pulling in misd/phone-number-bundle with composer is causing memory limit to be exhausted
- How to deal with numbers saved before phone-number-bundle implementation?
- Country choice custom text
- My form submission is always invalid HOT 3
- Missing require in composer HOT 2
- New release HOT 4
- Symfony templating component required HOT 2
- PhoneNumberValidatorTest fails on CI HOT 1
- Deprecations from Twig
- Allow multiple type HOT 2
- Add support for symfony 4.4 HOT 3
- Abandoned in favour of `odolbeau/phone-number-bundle` HOT 8
- Regular Expression Issue for Iranian Mobile
- Is this bundle abandoned? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phone-number-bundle.