Symfony – Use javascript in my modal form?

I’m trying to display a modal that contains the content of a form on Symfony.

I call my form with axios and I send it from my controller like this :

    $response = [
        "form" => $this->render("test/coupon/_form_edit_plans.html.twig", [
            "form" => $form->createView(),

    return new JsonResponse($response);

And my form :

<link href="[email protected]/dist/css/select2.min.css" rel="stylesheet" />

{{form_label(form.plans)}} <br>
<div class="custom-control custom-checkbox mb-1 ml-3">
    <input type="checkbox" class="custom-control-input" id="select-all">
    <label class="custom-control-label" for="select-all">Tout sélectionner</label>

<script src="[email protected]/dist/js/select2.min.js"></script>


            if($("#select-all").is(':checked') ){
                $(".plans > optgroup > option").prop("selected","selected");// Select All Options
                $(".plans").trigger("change");// Trigger change to select 2
                $(".plans > optgroup > option").prop("selected", false);
                $(".plans").trigger("change");// Trigger change to select 2

I manage to display it in my modal window, but the javascript part seems to be ignored. How can I force to accept javascript?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *