var/cache/dev/twig/5a/5adc3f67420368cfce6b2a8d4fedf7bd.php line 40

Open in your IDE?
  1. <?php
  2. use Twig\Environment;
  3. use Twig\Error\LoaderError;
  4. use Twig\Error\RuntimeError;
  5. use Twig\Extension\SandboxExtension;
  6. use Twig\Markup;
  7. use Twig\Sandbox\SecurityError;
  8. use Twig\Sandbox\SecurityNotAllowedTagError;
  9. use Twig\Sandbox\SecurityNotAllowedFilterError;
  10. use Twig\Sandbox\SecurityNotAllowedFunctionError;
  11. use Twig\Source;
  12. use Twig\Template;
  13. /* lidkaart/renew-membership.html.twig */
  14. class __TwigTemplate_297c34b826f797eb2d2fb17bfbf5ddc7 extends Template
  15. {
  16.     private $source;
  17.     private $macros = [];
  18.     public function __construct(Environment $env)
  19.     {
  20.         parent::__construct($env);
  21.         $this->source $this->getSourceContext();
  22.         $this->blocks = [
  23.             'content' => [$this'block_content'],
  24.         ];
  25.         $this->sandbox $this->env->getExtension('\Twig\Extension\SandboxExtension');
  26.         $this->checkSecurity();
  27.     }
  28.     protected function doGetParent(array $context)
  29.     {
  30.         // line 1
  31.         return $this->loadTemplate($this->extensions['App\Twig\Extension\WebsiteExtension']->getBaseLayout(), "lidkaart/renew-membership.html.twig"1);
  32.     }
  33.     protected function doDisplay(array $context, array $blocks = [])
  34.     {
  35.         $macros $this->macros;
  36.         $__internal_5a27a8ba21ca79b61932376b2fa922d2 $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
  37.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template""lidkaart/renew-membership.html.twig"));
  38.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
  39.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template""lidkaart/renew-membership.html.twig"));
  40.         $this->getParent($context)->display($contextarray_merge($this->blocks$blocks));
  41.         
  42.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
  43.         
  44.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
  45.     }
  46.     // line 3
  47.     public function block_content($context, array $blocks = [])
  48.     {
  49.         $macros $this->macros;
  50.         $__internal_5a27a8ba21ca79b61932376b2fa922d2 $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
  51.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""content"));
  52.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
  53.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""content"));
  54.         // line 4
  55.         echo "    <div class=\"row\">
  56.         <div class=\"col-8 mx-auto\">
  57.             <h1 class=\"py-5\">";
  58.         // line 6
  59.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Nieuwe lidkaart aanmaken"), "html"nulltrue);
  60.         echo "</h1>
  61.             ";
  62.         // line 7
  63.         $this->env->getRuntime("Symfony\\Component\\Form\\FormRenderer")->setTheme((isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'7$this->source); })()), [=> "bootstrap_5_layout.html.twig"], true);
  64.         // line 8
  65.         echo "
  66.             ";
  67.         // line 9
  68.         echo         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock($this->sandbox->ensureToStringAllowed((isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'9$this->source); })()), 9$this->source), 'form_start', ["attr" => ["class" => "form""id" => "membership_form"]]);
  69.         echo "
  70.             <div class=\"row\">
  71.                 <div class=\"col-lg-3\">
  72.                     ";
  73.         // line 12
  74.         echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'12$this->source); })()), "club", [], "any"falsefalsetrue12), 12$this->source), 'row', ["attr" => ["required" => "required"]]);
  75.         echo "
  76.                     ";
  77.         // line 13
  78.         echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'13$this->source); })()), "membershipType", [], "any"falsefalsetrue13), 13$this->source), 'row', ["attr" => ["required" => "required"]]);
  79.         echo "
  80.                 </div>
  81.                 <div class=\"col-lg-7\">
  82.                     <div class=\"p-3 m-3\" style=\"width: 18rem;\">
  83.                         <div class=\"d-flex justify-content-between\">
  84.                             <button type=\"button\" class=\"btn btn-secondary\" id=\"add_member\" disabled>";
  85.         // line 18
  86.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Lid Toevoegen"), "html"nulltrue);
  87.         echo "</button>
  88.                             <button type=\"submit\" class=\"btn btn-primary\" id=\"submit_button\" disabled>";
  89.         // line 19
  90.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Volgende"), "html"nulltrue);
  91.         echo "</button>
  92.                         </div>
  93.                     </div>
  94.                 </div>
  95.             </div>
  96.             <hr>
  97.             <div id=\"members\" class=\"row\" data-prototype=\"";
  98.         // line 25
  99.         echo twig_escape_filter($this->env$this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'25$this->source); })()), "members", [], "any"falsefalsetrue25), "vars", [], "any"falsefalsetrue25), "prototype", [], "any"falsefalsetrue25), 25$this->source), 'widget'));
  100.         echo "\">
  101.                 ";
  102.         // line 26
  103.         $context['_parent'] = $context;
  104.         $context['_seq'] = twig_ensure_traversable(twig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'26$this->source); })()), "members", [], "any"falsefalsetrue26));
  105.         $context['loop'] = [
  106.           'parent' => $context['_parent'],
  107.           'index0' => 0,
  108.           'index'  => 1,
  109.           'first'  => true,
  110.         ];
  111.         if (is_array($context['_seq']) || (is_object($context['_seq']) && $context['_seq'] instanceof \Countable)) {
  112.             $length count($context['_seq']);
  113.             $context['loop']['revindex0'] = $length 1;
  114.             $context['loop']['revindex'] = $length;
  115.             $context['loop']['length'] = $length;
  116.             $context['loop']['last'] = === $length;
  117.         }
  118.         foreach ($context['_seq'] as $context["_key"] => $context["MembershipFormType"]) {
  119.             // line 27
  120.             echo "                    <div class=\"col-lg-6 mb-4\" id=\"member_";
  121.             echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->source$context["loop"], "index", [], "any"falsefalsetrue27), 27$this->source), "html"nulltrue);
  122.             echo "\">
  123.                         ";
  124.             // line 28
  125.             echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($this->sandbox->ensureToStringAllowed($context["MembershipFormType"], 28$this->source), 'row');
  126.             echo "
  127.                         <button type=\"button\" class=\"btn btn-danger delete-member\" data-index=\"";
  128.             // line 29
  129.             echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->source$context["loop"], "index", [], "any"falsefalsetrue29), 29$this->source), "html"nulltrue);
  130.             echo "\">
  131.                             ";
  132.             // line 30
  133.             echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Remove Member"), "html"nulltrue);
  134.             echo "
  135.                         </button>
  136.                     </div>
  137.                 ";
  138.             ++$context['loop']['index0'];
  139.             ++$context['loop']['index'];
  140.             $context['loop']['first'] = false;
  141.             if (isset($context['loop']['length'])) {
  142.                 --$context['loop']['revindex0'];
  143.                 --$context['loop']['revindex'];
  144.                 $context['loop']['last'] = === $context['loop']['revindex0'];
  145.             }
  146.         }
  147.         $_parent $context['_parent'];
  148.         unset($context['_seq'], $context['_iterated'], $context['_key'], $context['MembershipFormType'], $context['_parent'], $context['loop']);
  149.         $context array_intersect_key($context$_parent) + $_parent;
  150.         // line 34
  151.         echo "            </div>
  152.             ";
  153.         // line 35
  154.         echo         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock($this->sandbox->ensureToStringAllowed((isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'35$this->source); })()), 35$this->source), 'form_end');
  155.         echo "
  156.         </div>
  157.     </div>
  158.     <script>
  159.         const sportChoices = {
  160.             'sailing': [
  161.                 'Zwaardboten',
  162.                 'Kitesurfen',
  163.                 'Yachting',
  164.             ],
  165.             'surfing': [
  166.                 'Windsurfen',
  167.                 'SUP',
  168.                 'Wingfoil',
  169.                 'Kitesurfen',
  170.             ]
  171.         }
  172.         function repopulateSportFields() {
  173.             const clubValue = \$('#";
  174.         // line 55
  175.         echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'55$this->source); })()), "club", [], "any"falsefalsetrue55), "vars", [], "any"falsefalsetrue55), "id", [], "any"falsefalsetrue55), 55$this->source), "html"nulltrue);
  176.         echo "').val();
  177.             const sportOptions = sportChoices[clubValue] || [];
  178.             // Iterate over all sport1 and sport2 selectors
  179.             \$('.sport1_selector').each(function(index, sport1Selector) {
  180.                 const \$sport1Selector = \$(sport1Selector);
  181.                 const currentSport1Selection = \$sport1Selector.val();
  182.                 // Reset the field options
  183.                 \$sport1Selector.empty();
  184.                 // Appending the default options
  185.                 sportOptions.forEach((element) => {
  186.                     const optionValue = element.toLowerCase();
  187.                     \$sport1Selector.append(\$('<option>', {value: optionValue}).text(element));
  188.                 });
  189.                 // Reapply the previous selection if it is still valid
  190.                 if (sportOptions.map(e => e.toLowerCase()).includes(currentSport1Selection)) {
  191.                     \$sport1Selector.val(currentSport1Selection);
  192.                 }
  193.             });
  194.             \$('.sport2_selector').each(function(index, sport2Selector) {
  195.                 const \$sport2Selector = \$(sport2Selector);
  196.                 const currentSport2Selection = \$sport2Selector.val();
  197.                 // Reset the field options
  198.                 \$sport2Selector.empty();
  199.                 // Setting the n.v.t. on the sport2 selector
  200.                 \$sport2Selector.append(\$('<option>', {value: 'N.V.T'}).text('N.V.T.'));
  201.                 // Appending the default options
  202.                 sportOptions.forEach((element) => {
  203.                     const optionValue = element.toLowerCase();
  204.                     \$sport2Selector.append(\$('<option>', {value: optionValue}).text(element));
  205.                 });
  206.                 // Reapply the previous selection if it is still valid
  207.                 if (sportOptions.map(e => e.toLowerCase()).includes(currentSport2Selection)) {
  208.                     \$sport2Selector.val(currentSport2Selection);
  209.                 } else {
  210.                     \$sport2Selector.val('N.V.T');
  211.                 }
  212.             });
  213.         }
  214.         // Function to enable/disable buttons based on form completion
  215.         function toggleButtons() {
  216.             const clubFilled = document.querySelector('#";
  217.         // line 105
  218.         echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'105$this->source); })()), "club", [], "any"falsefalsetrue105), "vars", [], "any"falsefalsetrue105), "id", [], "any"falsefalsetrue105), 105$this->source), "html"nulltrue);
  219.         echo "').value.trim() !== '';
  220.             const membershipType = document.querySelector('#";
  221.         // line 106
  222.         echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'106$this->source); })()), "membershipType", [], "any"falsefalsetrue106), "vars", [], "any"falsefalsetrue106), "id", [], "any"falsefalsetrue106), 106$this->source), "html"nulltrue);
  223.         echo "').value.trim();
  224.             const addParticipantButton = document.getElementById('add_member');
  225.             const submitButton = document.getElementById('submit_button');
  226.             const membersCount = document.querySelectorAll('#members .mb-4').length;
  227.             addParticipantButton.disabled = !(clubFilled && validateMembershipType(membershipType, membersCount));
  228.             submitButton.disabled = !(clubFilled && membershipType !== '' && membersCount >= 1);
  229.         }
  230.         // Validate membership type and number of members based on selected type
  231.         function validateMembershipType(type, count) {
  232.             const allowedMembers = {
  233.                 'jeugdlid': 1, // Limit for Jeugdlid - 22 j
  234.                 'volwassen': 1, // Limit for Volwassen
  235.                 'familie': 6, // Limit for Volwassen
  236.             };
  237.             if (type in allowedMembers) {
  238.                 if (count >= allowedMembers[type]) {
  239.                     return false;
  240.                 }
  241.             }
  242.             return true;
  243.         }
  244.         // Add Participant button functionality
  245.         document.getElementById('add_member').addEventListener('click', function () {
  246.             const collectionHolder = document.getElementById('members');
  247.             const prototype = collectionHolder.getAttribute('data-prototype');
  248.             const membershipType = document.querySelector('#";
  249.         // line 135
  250.         echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'135$this->source); })()), "membershipType", [], "any"falsefalsetrue135), "vars", [], "any"falsefalsetrue135), "id", [], "any"falsefalsetrue135), 135$this->source), "html"nulltrue);
  251.         echo "').value.trim();
  252.             const membersCount = document.querySelectorAll('#members .mb-4').length;
  253.             if (!validateMembershipType(membershipType, membersCount)) {
  254.                 return;
  255.             }
  256.             const index = collectionHolder.children.length;
  257.             const newForm = prototype.replace(/__name__/g, index);
  258.             const tempDiv = document.createElement('div');
  259.             tempDiv.innerHTML = newForm.trim();
  260.             const element = tempDiv.firstChild;
  261.             element.classList.add('col-lg-3', 'mb-4');
  262.             collectionHolder.appendChild(element);
  263.             const deleteButton = document.createElement('button');
  264.             deleteButton.setAttribute('type', 'button');
  265.             deleteButton.setAttribute('class', 'btn btn-danger delete-member my-2');
  266.             deleteButton.setAttribute('data-index', index);
  267.             deleteButton.innerHTML = '<i class=\"fa-solid fa-trash text-white\"></i>';
  268.             deleteButton.addEventListener('click', function () {
  269.                 if (confirm(\"";
  270.         // line 155
  271.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Are you sure you want to remove this member?"), "html"nulltrue);
  272.         echo "\")) {
  273.                     element.parentNode.removeChild(element);
  274.                     toggleButtons(); // Recheck form completion on member removal
  275.                 }
  276.             });
  277.             element.prepend(deleteButton);
  278.             toggleButtons(); // Recheck form completion on member addition
  279.             repopulateSportFields(); // Repopulate the sport fields based on the club entry
  280.         });
  281.         // Client-side form validation and button toggling
  282.         const form = document.getElementById('membership_form');
  283.         form.addEventListener('submit', function (event) {
  284.             if (!form.checkValidity()) {
  285.                 event.preventDefault();
  286.                 event.stopPropagation();
  287.             }
  288.             form.classList.add('was-validated');
  289.         });
  290.         // Control buttons activation based on input changes
  291.         document.querySelectorAll('input, select').forEach(input => {
  292.             input.addEventListener('input', toggleButtons);
  293.         });
  294.         toggleButtons(); // Initially check form completion on page load
  295.         \$('#";
  296.         // line 187
  297.         echo twig_escape_filter($this->env$this->sandbox->ensureToStringAllowed(twig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["form"]) || array_key_exists("form"$context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.'187$this->source); })()), "club", [], "any"falsefalsetrue187), "vars", [], "any"falsefalsetrue187), "id", [], "any"falsefalsetrue187), 187$this->source), "html"nulltrue);
  298.         echo "').on('change', function() {
  299.             repopulateSportFields(); // Repopulate the sport fields
  300.         });
  301.     </script>
  302. ";
  303.         
  304.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
  305.         
  306.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
  307.     }
  308.     public function getTemplateName()
  309.     {
  310.         return "lidkaart/renew-membership.html.twig";
  311.     }
  312.     public function isTraitable()
  313.     {
  314.         return false;
  315.     }
  316.     public function getDebugInfo()
  317.     {
  318.         return array (  338 => 187,  303 => 155,  280 => 135,  248 => 106,  244 => 105,  191 => 55,  168 => 35,  165 => 34,  147 => 30,  143 => 29,  139 => 28,  134 => 27,  117 => 26,  113 => 25,  104 => 19,  100 => 18,  92 => 13,  88 => 12,  82 => 9,  79 => 8,  77 => 7,  73 => 6,  69 => 4,  59 => 3,  37 => 1,);
  319.     }
  320.     public function getSourceContext()
  321.     {
  322.         return new Source("{% extends base_layout() %}
  323. {% block content %}
  324.     <div class=\"row\">
  325.         <div class=\"col-8 mx-auto\">
  326.             <h1 class=\"py-5\">{{ 'Nieuwe lidkaart aanmaken'|trans }}</h1>
  327.             {% form_theme form 'bootstrap_5_layout.html.twig' %}
  328.             {{ form_start(form, {'attr': {'class': 'form', 'id': 'membership_form'}}) }}
  329.             <div class=\"row\">
  330.                 <div class=\"col-lg-3\">
  331.                     {{ form_row(form.club, {'attr': {'required': 'required'}}) }}
  332.                     {{ form_row(form.membershipType, {'attr': {'required': 'required'}}) }}
  333.                 </div>
  334.                 <div class=\"col-lg-7\">
  335.                     <div class=\"p-3 m-3\" style=\"width: 18rem;\">
  336.                         <div class=\"d-flex justify-content-between\">
  337.                             <button type=\"button\" class=\"btn btn-secondary\" id=\"add_member\" disabled>{{ 'Lid Toevoegen'|trans }}</button>
  338.                             <button type=\"submit\" class=\"btn btn-primary\" id=\"submit_button\" disabled>{{ 'Volgende'|trans }}</button>
  339.                         </div>
  340.                     </div>
  341.                 </div>
  342.             </div>
  343.             <hr>
  344.             <div id=\"members\" class=\"row\" data-prototype=\"{{ form_widget(form.members.vars.prototype)|e }}\">
  345.                 {% for MembershipFormType in form.members %}
  346.                     <div class=\"col-lg-6 mb-4\" id=\"member_{{ loop.index }}\">
  347.                         {{ form_row(MembershipFormType) }}
  348.                         <button type=\"button\" class=\"btn btn-danger delete-member\" data-index=\"{{ loop.index }}\">
  349.                             {{ 'Remove Member'|trans }}
  350.                         </button>
  351.                     </div>
  352.                 {% endfor %}
  353.             </div>
  354.             {{ form_end(form) }}
  355.         </div>
  356.     </div>
  357.     <script>
  358.         const sportChoices = {
  359.             'sailing': [
  360.                 'Zwaardboten',
  361.                 'Kitesurfen',
  362.                 'Yachting',
  363.             ],
  364.             'surfing': [
  365.                 'Windsurfen',
  366.                 'SUP',
  367.                 'Wingfoil',
  368.                 'Kitesurfen',
  369.             ]
  370.         }
  371.         function repopulateSportFields() {
  372.             const clubValue = \$('#{{ form.club.vars.id }}').val();
  373.             const sportOptions = sportChoices[clubValue] || [];
  374.             // Iterate over all sport1 and sport2 selectors
  375.             \$('.sport1_selector').each(function(index, sport1Selector) {
  376.                 const \$sport1Selector = \$(sport1Selector);
  377.                 const currentSport1Selection = \$sport1Selector.val();
  378.                 // Reset the field options
  379.                 \$sport1Selector.empty();
  380.                 // Appending the default options
  381.                 sportOptions.forEach((element) => {
  382.                     const optionValue = element.toLowerCase();
  383.                     \$sport1Selector.append(\$('<option>', {value: optionValue}).text(element));
  384.                 });
  385.                 // Reapply the previous selection if it is still valid
  386.                 if (sportOptions.map(e => e.toLowerCase()).includes(currentSport1Selection)) {
  387.                     \$sport1Selector.val(currentSport1Selection);
  388.                 }
  389.             });
  390.             \$('.sport2_selector').each(function(index, sport2Selector) {
  391.                 const \$sport2Selector = \$(sport2Selector);
  392.                 const currentSport2Selection = \$sport2Selector.val();
  393.                 // Reset the field options
  394.                 \$sport2Selector.empty();
  395.                 // Setting the n.v.t. on the sport2 selector
  396.                 \$sport2Selector.append(\$('<option>', {value: 'N.V.T'}).text('N.V.T.'));
  397.                 // Appending the default options
  398.                 sportOptions.forEach((element) => {
  399.                     const optionValue = element.toLowerCase();
  400.                     \$sport2Selector.append(\$('<option>', {value: optionValue}).text(element));
  401.                 });
  402.                 // Reapply the previous selection if it is still valid
  403.                 if (sportOptions.map(e => e.toLowerCase()).includes(currentSport2Selection)) {
  404.                     \$sport2Selector.val(currentSport2Selection);
  405.                 } else {
  406.                     \$sport2Selector.val('N.V.T');
  407.                 }
  408.             });
  409.         }
  410.         // Function to enable/disable buttons based on form completion
  411.         function toggleButtons() {
  412.             const clubFilled = document.querySelector('#{{ form.club.vars.id }}').value.trim() !== '';
  413.             const membershipType = document.querySelector('#{{ form.membershipType.vars.id }}').value.trim();
  414.             const addParticipantButton = document.getElementById('add_member');
  415.             const submitButton = document.getElementById('submit_button');
  416.             const membersCount = document.querySelectorAll('#members .mb-4').length;
  417.             addParticipantButton.disabled = !(clubFilled && validateMembershipType(membershipType, membersCount));
  418.             submitButton.disabled = !(clubFilled && membershipType !== '' && membersCount >= 1);
  419.         }
  420.         // Validate membership type and number of members based on selected type
  421.         function validateMembershipType(type, count) {
  422.             const allowedMembers = {
  423.                 'jeugdlid': 1, // Limit for Jeugdlid - 22 j
  424.                 'volwassen': 1, // Limit for Volwassen
  425.                 'familie': 6, // Limit for Volwassen
  426.             };
  427.             if (type in allowedMembers) {
  428.                 if (count >= allowedMembers[type]) {
  429.                     return false;
  430.                 }
  431.             }
  432.             return true;
  433.         }
  434.         // Add Participant button functionality
  435.         document.getElementById('add_member').addEventListener('click', function () {
  436.             const collectionHolder = document.getElementById('members');
  437.             const prototype = collectionHolder.getAttribute('data-prototype');
  438.             const membershipType = document.querySelector('#{{ form.membershipType.vars.id }}').value.trim();
  439.             const membersCount = document.querySelectorAll('#members .mb-4').length;
  440.             if (!validateMembershipType(membershipType, membersCount)) {
  441.                 return;
  442.             }
  443.             const index = collectionHolder.children.length;
  444.             const newForm = prototype.replace(/__name__/g, index);
  445.             const tempDiv = document.createElement('div');
  446.             tempDiv.innerHTML = newForm.trim();
  447.             const element = tempDiv.firstChild;
  448.             element.classList.add('col-lg-3', 'mb-4');
  449.             collectionHolder.appendChild(element);
  450.             const deleteButton = document.createElement('button');
  451.             deleteButton.setAttribute('type', 'button');
  452.             deleteButton.setAttribute('class', 'btn btn-danger delete-member my-2');
  453.             deleteButton.setAttribute('data-index', index);
  454.             deleteButton.innerHTML = '<i class=\"fa-solid fa-trash text-white\"></i>';
  455.             deleteButton.addEventListener('click', function () {
  456.                 if (confirm(\"{{ 'Are you sure you want to remove this member?'|trans }}\")) {
  457.                     element.parentNode.removeChild(element);
  458.                     toggleButtons(); // Recheck form completion on member removal
  459.                 }
  460.             });
  461.             element.prepend(deleteButton);
  462.             toggleButtons(); // Recheck form completion on member addition
  463.             repopulateSportFields(); // Repopulate the sport fields based on the club entry
  464.         });
  465.         // Client-side form validation and button toggling
  466.         const form = document.getElementById('membership_form');
  467.         form.addEventListener('submit', function (event) {
  468.             if (!form.checkValidity()) {
  469.                 event.preventDefault();
  470.                 event.stopPropagation();
  471.             }
  472.             form.classList.add('was-validated');
  473.         });
  474.         // Control buttons activation based on input changes
  475.         document.querySelectorAll('input, select').forEach(input => {
  476.             input.addEventListener('input', toggleButtons);
  477.         });
  478.         toggleButtons(); // Initially check form completion on page load
  479.         \$('#{{ form.club.vars.id }}').on('change', function() {
  480.             repopulateSportFields(); // Repopulate the sport fields
  481.         });
  482.     </script>
  483. {% endblock %}
  484. ""lidkaart/renew-membership.html.twig""/var/www/clients/client2/web45/web/pc/templates/lidkaart/renew-membership.html.twig");
  485.     }
  486.     
  487.     public function checkSecurity()
  488.     {
  489.         static $tags = array("form_theme" => 7"for" => 26);
  490.         static $filters = array("escape" => 6"trans" => 6"e" => 25);
  491.         static $functions = array("form_start" => 9"form_row" => 12"form_widget" => 25"form_end" => 35"base_layout" => 1);
  492.         try {
  493.             $this->sandbox->checkSecurity(
  494.                 ['form_theme''for'],
  495.                 ['escape''trans''e'],
  496.                 ['form_start''form_row''form_widget''form_end''base_layout']
  497.             );
  498.         } catch (SecurityError $e) {
  499.             $e->setSourceContext($this->source);
  500.             if ($e instanceof SecurityNotAllowedTagError && isset($tags[$e->getTagName()])) {
  501.                 $e->setTemplateLine($tags[$e->getTagName()]);
  502.             } elseif ($e instanceof SecurityNotAllowedFilterError && isset($filters[$e->getFilterName()])) {
  503.                 $e->setTemplateLine($filters[$e->getFilterName()]);
  504.             } elseif ($e instanceof SecurityNotAllowedFunctionError && isset($functions[$e->getFunctionName()])) {
  505.                 $e->setTemplateLine($functions[$e->getFunctionName()]);
  506.             }
  507.             throw $e;
  508.         }
  509.     }
  510. }