A
A
Alexey Alekseev2019-02-01 17:46:31
symfony
Alexey Alekseev, 2019-02-01 17:46:31

Why is Select2 AJAX not being sent in Symfony 3.4?

In Symfony 3.4 I use Select2.

$builder->add('companycode', ChoiceType::class, array(
                'label' => 'Компания',
                'required' => false,
                'attr' => array('class' => 'ul-select'),
            ))


If I create Select2 like this:
$('.ul-select').select2({
    });

then everything works fine, the selected value is written to the database,

but if I return the data with AJAX:
$('.ul-select').select2({
        ajax: {
            url: '/customers/ulresponse',
            dataType: 'json',
            data: function (params) {
                return {
                    searchstr: params.term // search term
                };
            },
        },
        minimumInputLength: 3,
        language: 'ru',
    });


then after submitting the form, the symphony gives an error:

VALUE IS NOT ALLOWED

Although if you look at the parameters in the browser when submitting the form, the value is sent, but for some reason the symphony blocks the form submission.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question