Giter Club home page Giter Club logo

Comments (22)

chokrijobs avatar chokrijobs commented on May 25, 2024 5

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.

K0rell avatar K0rell commented on May 25, 2024 2

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 !

https://github.com/symfony/twig-bridge/blob/b3431c9214e3d386e53e16d63d716a85e8635e03/Resources/views/Form/form_div_layout.html.twig#L242

from phone-number-bundle.

prindacerk avatar prindacerk commented on May 25, 2024 1

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.

prindacerk avatar prindacerk commented on May 25, 2024 1

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.

iBasit avatar iBasit commented on May 25, 2024 1

no one is fixing this lol — This lib should not be used in prod anymore.

from phone-number-bundle.

JusteLeblanc avatar JusteLeblanc commented on May 25, 2024 1

@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.

chokrijobs avatar chokrijobs commented on May 25, 2024 1

@JusteLeblanc it works

from phone-number-bundle.

flopp26 avatar flopp26 commented on May 25, 2024 1

@chokrijobs thanks you for your solution ;-)

from phone-number-bundle.

thewilkybarkid avatar thewilkybarkid commented on May 25, 2024

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.

prindacerk avatar prindacerk commented on May 25, 2024

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.

thewilkybarkid avatar thewilkybarkid commented on May 25, 2024

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.

prindacerk avatar prindacerk commented on May 25, 2024

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.

thewilkybarkid avatar thewilkybarkid commented on May 25, 2024

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.

prindacerk avatar prindacerk commented on May 25, 2024

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.

StackTrace.txt

from phone-number-bundle.

thewilkybarkid avatar thewilkybarkid commented on May 25, 2024

No problem @prindacerk, glad you were able to solve it!

from phone-number-bundle.

K0rell avatar K0rell commented on May 25, 2024

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.

1988gadocansey avatar 1988gadocansey commented on May 25, 2024

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.

JusteLeblanc avatar JusteLeblanc commented on May 25, 2024

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.

nealio82 avatar nealio82 commented on May 25, 2024

Same here with Symfony 3.4 and EasyAdminBundle.

from phone-number-bundle.

numediaweb avatar numediaweb commented on May 25, 2024

@chokrijobs solution worked for me. Thanks!

from phone-number-bundle.

chokrijobs avatar chokrijobs commented on May 25, 2024

@numediaweb thank you too

from phone-number-bundle.

MatthieuPoullin avatar MatthieuPoullin commented on May 25, 2024

@1988gadocansey for symfony 4 you can use
{% form_theme form '@MisdPhoneNumber/Form/tel_bootstrap.html.twig' %}

from phone-number-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.