Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:44:58+00:00 2026-06-13T08:44:58+00:00

I am creating a dynamic form similar to what is wanted here . Well

  • 0

I am creating a dynamic form similar to what is wanted here.

Well i managed to get it working. But i would like that the native fields of the type could appear AFTER the dynamic dropdowns. This is not out of box because dropboxes are added to the form in the PRE_SET_DATA event (after the form is build and name field is added) as you can see:

public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('country', 'entity', array(
        'class'=>'TestBundle:Country', 
        'property'=>'name', 
        'property_path'=>false //Country is not directly related to City
    ));
    $builder->add('name');

    $factory = $builder->getFormFactory();

     (...)

     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshStates, $setCountry)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if($data == null)
            return;

        if($data instanceof City){
            $country = ($data->getId()) ? $data->getState()->getCountry() : null ;
            $refreshStates($form, $country);
            $setCountry($form, $country);
        }
    });

I tried to do the same for the name field adding this to the beginning of buildForm Function:

$addBaseFields = function ($form) use ($factory)
    {
        $form->add($factory->createNamed('text', 'name'));
    };

and then i added it in the event:

 $builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshStates, $setCountry)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if($data == null)
            return;

        if($data instanceof City){
            $country = ($data->getId()) ? $data->getState()->getCountry() : null ;
            $refreshStates($form, $country);
            $setCountry($form, $country);
            $addBaseFields($form);
        }
    });

This kind of works. But, html5 field validation stopped working. For example: if i define name as ‘number’ type instead of ‘text’: $form->add($factory->createNamed('number', 'name')); it will accept anything, any text.

Is there a better way to do this so i can still use number browser validation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:44:59+00:00Added an answer on June 13, 2026 at 8:44 am

    This is a Symfony Bug on versions 2.0 and 2.1 and has nothing to do with Form Events.

    When a string such ‘9fgda’ is input in a ‘number’ field, there is no validation error and the string value ‘9fgda’ is converted in the numeric value ‘9’ and gives no error.

    This is because of NumberFormatter and should be fixed for version 2.2.

    More information on this bug here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating dynamic templated XAML designs that I would like to convert to PNG
I have a dynamic form that i am creating in php then i have
I am working on rendering a dynamic form in an ASP.NET MVC view that
How would I go about creating a dynamic hole in a windows form through
I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears
I need to integrate the functionality of creating dynamic pages (like google sites) to
I have a scenario that, I am creating dynamic html content and I need
I'm creating a dynamic responsive week calendar, using Twitter Bootstrap . Here's my current
I am creating a dynamic form in Access 2003. Each time the form is
I'm using AngularJS with Rails and creating dynamic nested form items which are not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.