1

I just the following tutorial from official website select2 and get the error and this is the code

$('.tags').select2({
    multiple: true,
    tags: true
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.css" rel="stylesheet"/>

<select class="form-control tags" name="tags[]">
  <option selected="selected">orange</option>
  <option>white</option>
  <option selected="selected">purple</option>
</select>

and error in the console like this enter image description here

this is javascript code

$('.tags').select2({
     theme: 'bootstrap',
     tags: true
})

anyone can help me to solve the problem? <>

Bonny AUlia
  • 95
  • 2
  • 10

1 Answers1

0

To avoid inifinite loop use trigger method parameters to distinguish event calls, in trigger method usage add parameter and in event callback check if paramater exists, when parameter exists that means that event was triggered from code, if no, that means it is event from ui.

Checkout: Select2 trigger("change") creates an infinite loop

EdwinN1337
  • 551
  • 5
  • 4
  • It sounds interesting considering the stack trace. –  Mar 02 '19 at 09:39
  • @BonnyAUlia Same kind of problem : https://github.com/select2/select2/issues/2883. –  Mar 02 '19 at 09:48
  • i dont know how to tell what exactly problem, because nothing diff between select2 and jquery version what i use in snippet and implementation code. The problem show if i try to type something in select2 multiple with log error Maximum call stack size exceeded. and i try to trigger the problem was same. thanks @leaf – Bonny AUlia Mar 02 '19 at 10:05
  • @BonnyAUlia So the problem occurs when you type something (even with the code snippet ?), here is an important piece of information. –  Mar 02 '19 at 11:12