In rails 4.2.2, I am using chosen jquery plugin for dropdown(multiple) field inside a modal form. Right now form & field is loading with no errors but collection(list) is not loading, if I try to search then it shows "No results...".

在rails 4.2.2中,我在模态表单中使用选择的jquery插件用于下拉(多个)字段。现在表单和字段正在加载没有错误但收集(列表)没有加载,如果我尝试搜索然后它显示“没有结果......”。

In controller,

@users = User.all.collect(&:name)

In views,

<%= f.input :users, :as =>:select, :label=>false, :collection =>[], :input_html=>{:multiple=>true, :class=>"form-control"} %>

In view.js.erb

var content = "<%= escape_javascript(render(:partial=>"form")) %>";
var container = $('#main-lightbox-container');
container.find('.modal-content').html(content);
container.modal({});

initializeMultipleChoose("#event_users", JSON.parse('<%= raw(@users) %>'), {width: "95%", max_selected_options: 5, allow_single_deselect: true});
$("#event_users").trigger("chosen:updated");

In custom .js file,

在自定义.js文件中,

function initializeMultipleChoose(id, selectedOptions, parameters){
  selectedOptionsArray = $.isArray(selectedOptions) ? selectedOptions : [selectedOptions]
  object = $(id);
  $.each(object.find("option"), function(key, content){
    option = object.find(content);
    if(selectedOptionsArray.indexOf(option.val())> -1)
        option.attr('selected',true);
  })
  object.chosen(parameters);
}

What I need to do for loading a list? Please help me.

我需要做什么才能加载列表?请帮我。

1 个解决方案

#1


0

Maybe the reason is that you are trying to init the chosen plugin BEFORE the HTML DOM is available? Could you check?

也许原因是你在HTML DOM可用之前尝试初始化所选的插件?你能检查一下吗?

更多相关文章

  1. 阻止用户在表单字段中输入
  2. CORS错误:请求标头字段预检响应中的Access-Control-Allow-Headers
  3. 如何在选择单选按钮时显示文本字段
  4. 将输入文本字段显示为纯文本
  5. 在用户将'n'粘贴复制到文本字段后,如何更新视图模型?
  6. 带有无线电的JavaScript条件字段不起作用
  7. 如何在onchange()事件后调用的方法中将焦点设置为输入字段?
  8. 无法在JQuery中查找表单输入
  9. 用于转换单位的HTML和JavaScript表单

随机推荐

  1. MySQL数据库相关开发入门
  2. php&input复选框存储每个循环的值
  3. MySQL使用二进制日志来恢复数据
  4. windows下安装mysql5.6解压版,32位和64位
  5. Mysql的存储引擎之:MyISAM存储引擎
  6. Mysql基础之 基础知识解释
  7. 如何向mysql数据库添加多个映像?
  8. Sql查询性能限制行数之间的差异
  9. PHP分页算法详解
  10. mysql忘记帐号密码 解决办法。