EasyAdmin Bundle创建的下拉列表在选择时未关闭

时间:2019-05-15 18:46:36

标签: symfony google-chrome easyadmin

我正在使用easyadmin捆绑包创建我的Symfony4.2网站的后端。在为我的实体创建的新/编辑表单中,它会创建一个下拉菜单供您选择。但是,在chrome和firefox中,这些下拉列表的行为不符合预期。当我单击它们时,它显示选项,但是如果我选择一个选项或单击下拉菜单,它不会关闭。可以在Safari和Edge上正常运行。

这是easyadmin.yaml

easy_admin:
    #Global Settings
    site_name: 'Physics Quiz SIte'

    design:
        assets:
            favicon: '/build/images/favicon.ba133a8b.ico'
    # this is the default form theme used by backends
        form_theme: '@EasyAdmin/form/bootstrap_4.html.twig'
    # these custom templates are applied to all entities
        brand_color: '#1ABC9C'
        menu:
            - { label: 'Public Homepage', route: 'homepage', icon: 'home' }
            - { entity: 'User', icon: 'user' }
            - { entity: 'QuestionType' }
            - { entity: 'Question' }
            - { entity: 'Quiz' }

    show:
        max_results: 10

    list:
        actions:
            - { name: 'edit', icon: 'pencil'}
            - { name: 'delete', icon: 'trash'}
        # allow deleting multiple items at once ...
        batch_actions: ['delete']

    # List the entity class name you want to manage
    entities:
        Quiz:
            class: App\Entity\Quiz
            form:
                fields:
                -   property: 'quizname'
                    label: 'Quiz Name'
                -   property: 'course'
                    type: 'entity'
                    type_options:
                        expanded: false
                        multiple: false

这是创建的相关页面源:

<div class="col-12 ">
 <div class="form-group  field-entity">
  <label class="form-control-label required" for="quiz_course">Course</label>
  <div class="form-widget">
   <select id="quiz_course" name="quiz[course]" data-widget="select2" class="form-control">
    <option value="1">Year 10 Physics</option>
    <option value="2">Year 11 Physics</option>
   </select>
  </div>
 </div>
</div>

这是可能相关的脚本。

<script src="/bundles/easyadmin/select2/i18n/en.js"></script>
<script type="text/javascript">
  $(function() {
    // Select2 widget is only enabled for the <select> elements which
    // explicitly ask for it

    function init() {
      $('form select[data-widget="select2"]').select2({
        theme: 'bootstrap',
        language: 'en'
      });
    }

    $(document).on('easyadmin.collection.item-added', init);
    init();
  });
</script>

这是呈现的下拉菜单的图片:

enter image description here

1 个答案:

答案 0 :(得分:3)

这是版本2.1.2中引入的错误。

https://github.com/EasyCorp/EasyAdminBundle/issues/2715

有一个新版本2.1.3解决了该问题。