4 examples of 'select2 multiple select all' in JavaScript

Every line of 'select2 multiple select all' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
64function setMultipleSelectOptions(nextSelectedIndex) {
65 set(_state => {
66 const selectedOptionsArray = _state.selectedOptions.slice();
67
68 if (selectedOptionsArray.includes(nextSelectedIndex)) {
69 const index = selectedOptionsArray.indexOf(nextSelectedIndex);
70 selectedOptionsArray.splice(index, 1);
71 } else {
72 selectedOptionsArray.push(nextSelectedIndex);
73 }
74
75 return {
76 ..._state,
77 isPopoverOpen: true,
78 activeOption: nextSelectedIndex,
79 selectedOptions: selectedOptionsArray,
80 };
81 });
82}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

397function init_select2(selector, type, data, selected, placeholder, config) {
398 var $select = $(selector);
399
400 // allow function to be assigned to pass data
401 var data_function = function(params) {
402 data.term = params.term;
403 data.page = params.page || 1;
404 return data;
405 };
406 if ($.isFunction(data)) {
407 data_function = data;
408 }
409
410 var init = {
411 theme: "bootstrap",
412 dropdownAutoWidth : true,
413 width: "auto",
414 placeholder: placeholder,
415 allowClear: true,
416 ajax: {
417 url: ajax_url + '/select/' + type,
418 delay: 150,
419 data: data_function
420 }
421 };
422
423 // override init values
424 if (typeof config === 'object') {
425 const keys = Object.keys(config)
426 for (const key of keys) {
427 init[key] = config[key];
428 }
429 }
430
431 $select.select2(init);
432
433 if (selected) {
434 console.log(selected);
435 if (typeof selected !== 'object') {
436 selected = {id: selected, text: selected};
437 }
438
439 var newOption = new Option(selected.text, selected.id, true, true);
440 $select.append(newOption).trigger('change');
441 }
442}
233private initModelWithMultipleMode(): void {
234 if (!this.model || !this.multiple || !this.selectOptions.length) return
235 if (!Array.isArray(this.model)) this.model = [this.model]
236
237 this.multipleLabels = this.model
238 .map((item: any) => {
239 const option: SelectOption = this.selectOptions.find(option => option.value === item)
240 if (option && option.label) return option.label
241 return null
242 })
243 .filter((r: any) => !!r)
244 this.updateLayoutWithMultipleMode()
245}
234function multipleSelect(mode){
235 var element_id = parseInt($("#multipleSelectionTool").data('img_container_id').split("___")[1]);
236 $(".img_container").each(function(){
237 if(!$(this).hasClass("image_selected")){
238
239 // Update the session list
240 updateListSession($(this).attr("id"), "selected", "gallery")
241
242 if (mode=='all'
243 || (mode=='from' && $(this).attr('id').split("___")[1]>element_id)
244 || (mode=='to' && $(this).attr('id').split("___")[1]<element_id)) {
245 $(this).addClass("image_selected")
246 }
247 }
248
249 })
250}

Related snippets