Nette Forms toggle checkbox a volanie zmana stavu javascriptom

duskohu
Člen | 778
+
0
-

Ahojte mam checkbox na ktorom mam toggle, a snazim sa pomocou js menit stav checkboxu na true/false, checkbox meni svoj stav ale funkcia toggle sa mi nespusta. Spusta sa to po ajax requeste, ted to skusam mimo requestu tak to funguje. Neviete mi poradit co mam zle?

$form->addCheckbox("isCompany", 'Firma')
->addCondition($form::EQUAL, true)
->toggle('company-container');
(function($, undefined) {
  $.nette.ext('orderClientFillForm', {
    load: function() {

      $('select[data-order-client-fill-form]').each(function() {
        let $this = $(this);
        let $link = $this.data('orderClientFillForm');
        let $filterAlias = 'clientId';

        //$this.off('change');
        $this.on('change', function(e) {

          let $value = $($this).find('option:selected').val();
          let $url = $link.replace('%25' + $filterAlias + '%25', $value);

          $.ajax($url, {
            success: function(payload) {
              $.each(payload, function(key, value) {
                let $elm = $('#' + key);
                if ($elm.length > 0) {
                  if ($($elm).is('select')) {
                    $elm.val(value).trigger('change');
                  } else if ($($elm).is(':checkbox')) {
                    $elm.attr('checked', value); // tato cast ma problem
                    $elm.trigger('change');
                  } else {
                    $elm.val(value).trigger('change');
                  }
                }
              });
            },
          });
        });
      });
    },
  });
})(jQuery);

Editoval duskohu (2. 2. 2021 8:24)