Symfony multiselect dropdown not working for second form type

问题内容:

I am rendering two form types on a page from my project. I do this because my users have to decide between two options, how to proceed, which are very similar and include 3 dropdowns for the same entities.

     <div id="upload_profile_yes" >
      <div id="up_markets_container" class="col-md-4">
        {{ form_row(upForm.markets, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id="up_channel1_container" class="col-md-4">
        {{ form_row(upForm.channel1, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id = "up_prod_container" class="col-md-4">
        {{ form_row(upForm.products, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id ="up_container" class="col-md-12">
        {{ form_row(upForm.uploadprofile) }} <br>
      </div>
    </div>

    <div id="upload_profile_no">
      <div id="markets_container" class="col-md-4">
        {{ form_row(form.markets, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id="channel1_container" class="col-md-4">
        {{ form_row(form.channel1, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id = "prod_container" class="col-md-4">
        {{ form_row(form.products, { 'attr': { 'class': 'form-inline'} }) }}
      </div>
      <div id="agencies_container" class="col-md-12">
        {{ form_row(form.agencies) }}
      </div>
    </div>

    <br>
  </div>
</div>

<script src="{{ asset('js/bootstrap-datepicker.js') }}"></script>
<script src="{{ asset('js/moment.min.js') }}"></script>
<script src="{{ asset('js/bootstrap-multiselect.js') }}"></script>

{# JS functions to validate IATA/UCID/tourcode (and possibly load funds) #}
{% include 'AppBundle:Utils:validation.js.twig' %}
{% include 'DocumentBundle:Document/Utils:agency_selection.js.twig' %}
{% include 'DocumentBundle:Document/Utils:uploadprofile_selection.js.twig' %}

So for the first choice (upload_profile_no) I use the javascript file agency_selection.js.twig (cut down to the necessary code)

 <script type="text/javascript">

makeMultiselectDropdown('#{{ form.vars.name }}_markets', 'Select Markets' );
makeMultiselectDropdown('#{{ form.vars.name }}_products', 'Select Products' );
makeMultiselectDropdown('#{{ form.vars.name }}_channel1', 'Select Channel1');

</script>

this results in all of the three dropdowns becoming a multiselect like the way I want it. For the second choice (upload_profile_yes) I have the uploadprofile_selection.js.twig file

<script type="text/javascript">
alert('#{{ upForm.vars.name }}_markets');
makeMultiselectDropdown('#{{ upForm.vars.name }}_markets', 'Select Markets' );
makeMultiselectDropdown('#{{ upForm.vars.name }}_products', 'Select Products' );
makeMultiselectDropdown('#{{ upForm.vars.name }}_channel1', 'Select Channel1' );

      </script>

but for this form, it’s just simply not rendering the multiselect dropdowns.
The form is rendered correctly, so the dropdowns appear on the correct spot with the correct data, but the javascript for making them real dropdowns doesn’t work.

The javascript file is working (I tested it with the alert() function, and that’s working..)

问题评论:

原文地址:

https://stackoverflow.com/questions/47755985/symfony-multiselect-dropdown-not-working-for-second-form-type

添加评论