0

I have a flask-admin form, where when user select the topmost dropdown field, certain fields in this form must change into Select2 (dropdown) field. This is what I have so far:

for(var idx in formData.custom_field_chooser)
    {
        var custom_field = $('#' + idx);
        custom_field.select2(); //This generate error
    }

I think my code is correct, but that custom_field.select2() code geneate this error Uncaught query function not defined for Select2 undefined.

Now, I am sure Select2 has already been included by flask-admin (cmiiw), but how do we use that?

swdev
  • 4,997
  • 8
  • 64
  • 106

1 Answers1

0

Finally looking at the trivial error message Uncaught query function not defined for Select2, this post in SO solved my problem. This is how you properly initialized an empty Select2:

custom_field.select2({
 data: {
   id: "",
   text: ""
  }
 });

This will change that custom_field element into select2.

Community
  • 1
  • 1
swdev
  • 4,997
  • 8
  • 64
  • 106