From 20ae34caaa92b3b84010900287ea6a9957f59c84 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 25 Oct 2019 15:44:23 +0800 Subject: [PATCH] competition setting: select school --- .../admins/competition_settings/index.js | 28 +++++++++++++++++++ .../competition_settings/index.html.erb | 20 ++++--------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js index 9eb53d529..ec4b14ead 100644 --- a/app/assets/javascripts/admins/competition_settings/index.js +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -107,6 +107,34 @@ $(document).on('turbolinks:load', function(){ } }); }); + + var selectOptions = { + theme: 'bootstrap4', + placeholder: '请输入要添加的单位名称', + multiple: true, + minimumInputLength: 1, + ajax: { + delay: 500, + url: '/api/schools/for_option.json', + dataType: 'json', + data: function(params){ + return { keyword: params.term }; + }, + processResults: function(data){ + return { results: data.schools } + } + }, + templateResult: function (item) { + if(!item.id || item.id === '') return item.text; + return item.name || item.text; + }, + templateSelection: function(item){ + return item.name || item.text; + } + } + + $('.sponsor-select').select2(selectOptions); + $('.allow-school-select').select2(selectOptions); } }); diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 44e3da7ee..1e20e20fb 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -97,13 +97,8 @@
主办方
-
- + - +
+ <%= select_tag :sponsor_ids, options_for_select([], nil), class: 'form-control sponsor-select' %>
@@ -111,13 +106,8 @@
开放范围
-
- + - +
+ <%= select_tag :allow_school_ids, options_for_select([], nil), class: 'form-control allow-school-select' %>
@@ -481,4 +471,4 @@ -<% end %> +<% end %> \ No newline at end of file