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 6718909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:01:49+00:00 2026-05-26T09:01:49+00:00

For a while now I’ve been wrestling with the issue of dynamic forms that

  • 0

For a while now I’ve been wrestling with the issue of dynamic forms that change depending on previous input. This is my first Symfony project, so I’m still getting the hang of how everything works together.

What I have is a form type for selecting periods of time. There are preset periods (such as 1min, 5min, 30min, 1hour etc) and a custom text box for entering a certain number of seconds. This form can be embedded in other forms, so (afaik) doesn’t have a standard ID that can be accessed. I would like the custom time text box to be only visible if the “Custom Time” (empty value) is selected from the preset time list.

Alternately, the preset values could just write a value in seconds to the custom value (and would need to have the preset box changed to custom on modification of the custom text box). That would be acceptable too.

If the form builder wasn’t being used, this would be trivial JavaScript but rather than hacking something together, I would much rather do it properly in reusable code so that I know for the future. To my way of thinking, if there was a way of specifying a custom form rendering template in the form type itself that applied only to that form, that would be fantastic.

Fingers crossed that there’s a good solution to this!

Edited: Also, I’m using Twig for rendering all my views.

  • 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-05-26T09:01:50+00:00Added an answer on May 26, 2026 at 9:01 am

    Results of a bit of research concluded that the best way to do this is to add field overrides for the widget:

    /src/PWT/DataBundle/Resources/views/Form/fields.html.twig:

    {% block periodChoose_widget %}
        <script type="text/javascript" src="{{ asset('bundles/databundle/js/periodChoose.js') }}"></script>
        {{ block('form_widget') }}
    {% block %}
    

    Then add the following to each of the app/bundle config files:

    /app/config/config.yml:

    imports:
        data_bundle:
            resource: @PWTDataBundle/Resources/config/config.yml
    

    /src/PWT/DataBundle/Resources/config/config.yml:

    # Twig Configuration
    twig:
        form:
            resources:
                - 'PWTDataBundle:Form:fields.html.twig'
    

    I realized that I would need to add something in the global app config if I wanted to reuse the form across multiple bundles. This allows the bundle to be reasonably self contained, with only a small reference in the overall app config. The javascript is not included until the form is used, and the twig block has very little overhead compared to other solutions (afaik).

    This way, the javascript that goes with the form is included whenever it is used, and to modify it only requires modification of the bundle, not anything in the overall app config/views. It also breaks the views up so that they don’t have a long list of extends this, extends that (like would need to be applied if you had a bundle style that added formTheme tag to override on the base bundle template).

    Some of those last 2 paragraphs is speculation, and there could easily be a far better way to do this but this is an adequate fit for me to move on. If anyone has a better solution, I would be happy to read about it.

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

Sidebar

Related Questions

Been trying to solve this for a while now. I need a regex to
I have been mauling over this for while now, and wonder if anyone could
Summary It's been while now that I receive emails on a specific work-related domain,
I've been googling for a while now... Ok, I'm sorry, this one is pathetically
Been staring at this problem for a while now. Here's the error I'm getting
For a while now I've been wrestling with how best to handle hierarchies in
Been beating about this problem for a while now. Under IIS6 and windows authentication,
I'm having this problem for a while now. I tried so many things that
I've been programming a while now at school, and I'm working on my first
It's been a while now since Microsoft stopped supporting Embedded Visual C++ 4.0 (eVC

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.