Select2 容器在简单模式对话框中显示后没有偏移

Select2 container has no offset after being shown in a simplemodal dialog

我在 Rails 页面上有一个 Ruby 循环遍历一组实体,为每个实体生成一个编辑表单。它使用 3.4.3 的 select2 作为 select_tag.

形式:

#EditPublicPlacesForms
  - @public_places.each do |p|
    = form_for p, url: place_customer_path(@customer.id), html: { id: "place_#{p.id}" } do |f|
      = f.label :service_profile_id, t('hss.views.subscribers.new.service_profile')
      = f.select :profile_id, options_from_collection_for_select(@profiles, 'id', 'name', p.profile_id), {include_blank: true}, {'data-placeholder' => t('pro.views.customers.new.profile_selection'), id: "profile_id_#{pi.id}"}
    << other parts of form >>>

此表单使用基本的简单模式对话框命令显示:

$('#EditPublicIdentityForms').modal
  minHeight: '40%'
  minWidth: '50%'

这是用例:显示表单、关闭表单、再次显示表单。第一个问题是 select2 的 container.offset 在第二个显示器上未定义。这使得select2列表显示在页面的左上角。

第二个问题是,当单击 select2 字段时,生成的任何其他表单都会抛出 javascript 错误 "Uncaught TypeError: Cannot read property 'top' of undefined"。因此,我无法在编辑一个页面后编辑页面上的任何其他项目。

我试过为 select_tag 生成一个唯一的 ID。我试过在模态 onClose 事件中销毁 select2。为什么 select2 在任何后续显示中都没有与原始容器相关联? simplemodal 关闭对话框对 select2 容器做了什么?

问题似乎是 simplemodal 没有持久化容器。容器不会在后续调用中重建。在模态调用中加入persist:true的选项,问题似乎解决了。