|
261 | 261 | // awesome markdown editor |
262 | 262 | self.simple_markdown_editor = create_easyMDE(self.refs.description) |
263 | 263 |
|
| 264 | + // Custom menu template that renders description under the item name |
| 265 | + // data-text is set to name-only so that selected labels show only the title |
| 266 | + var dropdown_menu_template = function(response) { |
| 267 | + var html = '' |
| 268 | + $.each(response.values, function(index, item) { |
| 269 | + let name = item.name || '' |
| 270 | + let value = item.value || '' |
| 271 | + let description = item.description |
| 272 | + html += '<div class="item" data-value="' + value + '" data-text="' + name + '">' |
| 273 | + html += '<strong>' + name + '</strong>' |
| 274 | + if (description) { |
| 275 | + html += '<div class="dropdown-item-description">' + description + '</div>' |
| 276 | + } |
| 277 | + html += '</div>' |
| 278 | + }) |
| 279 | + return html |
| 280 | + } |
| 281 | + |
264 | 282 | // semantic multiselect |
265 | 283 | $(self.refs.multiselect).dropdown({ |
266 | 284 | apiSettings: { |
|
270 | 288 | return {success: true, results: _.values(data.results)} |
271 | 289 | }, |
272 | 290 | }, |
| 291 | + templates: {menu: dropdown_menu_template}, |
273 | 292 | onAdd: self.task_added, |
274 | 293 | onRemove: self.task_removed, |
275 | 294 | }) |
|
282 | 301 | return {success: true, results: _.values(data.results)} |
283 | 302 | }, |
284 | 303 | }, |
| 304 | + templates: {menu: dropdown_menu_template}, |
285 | 305 | onAdd: self.public_data_added, |
286 | 306 | onRemove: self.public_data_removed, |
287 | 307 | }) |
288 | | - |
| 308 | + |
289 | 309 | $(self.refs.starting_kit_multiselect).dropdown({ |
290 | 310 | apiSettings: { |
291 | 311 | url: `${URLS.API}datasets/?search={query}&type=starting_kit`, |
|
294 | 314 | return {success: true, results: _.values(data.results)} |
295 | 315 | }, |
296 | 316 | }, |
| 317 | + templates: {menu: dropdown_menu_template}, |
297 | 318 | onAdd: self.starting_kit_added, |
298 | 319 | onRemove: self.starting_kit_removed, |
299 | 320 | }) |
|
858 | 879 | <style type="text/stylus"> |
859 | 880 | .chevron, .icon-button |
860 | 881 | cursor pointer |
| 882 | + .dropdown-item-description |
| 883 | + font-size 0.85em |
| 884 | + color rgba(0,0,0,0.5) |
| 885 | + margin-top 2px |
| 886 | + white-space normal |
| 887 | + line-height 1.3 |
861 | 888 | </style> |
862 | 889 | </competition-phases> |
0 commit comments