Query function not defined for Select2 undefined error

23,493 views
Skip to first unread message

bhabishyat

unread,
Jul 12, 2012, 3:39:26 AM7/12/12
to sel...@googlegroups.com
Hi,

I am using dojo for my application and have used select2 for my select boxes. I have built simple function as follows:

function loadSelect()
{
$(".form-select").select2({
        placeholder: "Select Anyone"
});
}

This function is called by dojo's dojo.behaviour.apply(). On page load, the select2 is working properly and the select elements are rendered using select2. I am using dojo to generate a form using ajax and place it in the dom. Once i add a new form using ajax, the select2 is not used by added select elements. The behaviour.apply() function is called every time a new form is added ( so is the loadSelect()). But i get an error as "query function not defined for Select2 undefined error" . Can you help me fix the error? I am not sure what causes the error and what i should do to fix it.

Also is there a dojo port for select2 so that i dont have to use both dojo and jquery?

Thanks.

Igor Vaynberg

unread,
Jul 12, 2012, 4:20:11 AM7/12/12
to sel...@googlegroups.com
On Thu, Jul 12, 2012 at 10:39 AM, bhabishyat <bhabi...@gmail.com> wrote:
> Hi,
>
> I am using dojo for my application and have used select2 for my select
> boxes. I have built simple function as follows:
>
> function loadSelect()
> {
> $(".form-select").select2({
> placeholder: "Select Anyone"
> });
> }
>
> This function is called by dojo's dojo.behaviour.apply(). On page load, the
> select2 is working properly and the select elements are rendered using
> select2. I am using dojo to generate a form using ajax and place it in the
> dom. Once i add a new form using ajax, the select2 is not used by added
> select elements. The behaviour.apply() function is called every time a new
> form is added ( so is the loadSelect()). But i get an error as "query
> function not defined for Select2 undefined error" . Can you help me fix the
> error? I am not sure what causes the error and what i should do to fix it.

i believe this error happens because you do not attach select2 to a
select tag...so double check what tag select2 sees.

> Also is there a dojo port for select2 so that i dont have to use both dojo
> and jquery?

i dont think a port is possible, it would have to be a rewrite.

-igor

>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "select2" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/select2/-/cczza3PkaLIJ.
> To post to this group, send email to sel...@googlegroups.com.
> To unsubscribe from this group, send email to
> select2+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/select2?hl=en.

bhabishyat

unread,
Jul 12, 2012, 5:25:36 AM7/12/12
to sel...@googlegroups.com
Hi Igor,

Thanks for the reply. I got it working now.

The problem was because of the extra div that was being added by the select2. Select2 had added new div with class "select2-container form-select" to wrap the select created. So the next time i loaded the function, the error was being thrown as select2 was being attached to the div element. I changed my selector as:

$('select.form-select').select2({
 placeholder:"Select Anyone"
}); 

and its working now.
Thanks a lot.

agg....@gmail.com

unread,
Jul 30, 2012, 2:35:25 PM7/30/12
to sel...@googlegroups.com
Not sure if anyone is facing the same issue but i got this error too when i was making an ajax call to the backend but was missing the "query" object in the object literal for select2

Varun
> > select2+u...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages