Ajax genemu_jqueryselect2_hidden: "query function not defined"
Opened this issue · 2 comments
Hello,
I am trying to use the select2 element for an ajax-loaded Symfony form.
As I read in the docs, I have to use a genemu_jqueryselect2_hidden type
for ajax instead of a genemu_jqueryselect2_choice, since changing the options
of a choice will cause the form to not be validated by Symfony.
However, I took the code from the docs
(whithout the config merging-part, because I don't need any custom configs)
and I do get a select2 element, but on page load the following exception is thrown:
uncaught exception: query function not defined for Select2 my_id
As I understand, the below code (from https://github.com/genemu/GenemuFormBundle/blob/master/Resources/doc/jquery/select2/ajax.md)
should define the query function.
in the form type:
$formbuilder->add('my_id', 'genemu_jqueryselect2_hidden', array(
'label' => 'my_label',
'required' => true,
));
in the javascript code inside the twig template:
$configs = {
query: function (query)
{
var data = {results: []}, i, j, s;
for (i = 1; i < 5; i++) {
s = "";
for (j = 0; j < i; j++) {s = s + query.term;}
data.results.push({id: query.term + i, text: s});
}
query.callback(data);
}
};
// end of custom configs
$('#my_id').select2($configs);
The exception happens after the execution of this code.
Is this a bug or am I doing something wrong?
Thanks in advance
I'm having exactly the same problem.
Dito! Related to #330 .