Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netteForms.js: Stack overflow and Too much recursions on CheckboxList #143

Closed
radekdostal opened this issue Feb 10, 2017 · 7 comments
Closed

Comments

@radekdostal
Copy link
Contributor

@radekdostal radekdostal commented Feb 10, 2017

  • bug report? yes
  • feature request? no
  • version: 2.4.3

Description

I have form component with four CheckboxLists. There are set own validation rules (PHP, JavaScript), but if these rules are removed, error is still thrown. The entire form contains only four checkboxes and a submit button. The form is manually rendered and Firefox Console is blank. If I leave the tab and come back, console contains "too much recursion" and "stack overflow" on this line and this line. Javascript validation during form submitting fails, own validation rules are not called.

When I use netteForms.js version 2.3.10, everything is ok and JavaScript validation passes.

data-nette-rules attributes are the same for Nette 2.3.10 and Nette 2.4.0 (20170119).

Steps To Reproduce

  public function getControl()
  {
    $this->setOption('rendered', TRUE);

    $form = new Form();
    $container = $form->addContainer($this->getHtmlName());

    $regions = $municipalities = $departments = [];

    if ($this->regionsEnabled === TRUE)
    {
      $regions = $container->addCheckboxList('regions', NULL, $this->regionsList);
      $regions->setDefaultValue($this->regions)
        ->getSeparatorPrototype()
        ->setName(NULL);
      $regions->getLabelPrototype()
        ->setClass('checkbox-inline');
    }

    if ($this->municipalitiesEnabled === TRUE)
    {
      $municipalities = $container->addCheckboxList('municipalities', NULL, $this->municipalitiesList);
      $municipalities->setDefaultValue($this->municipalities)
        ->getSeparatorPrototype()
        ->setName(NULL);
      $municipalities->getLabelPrototype()
        ->setClass('checkbox-inline');
    }

    if ($this->departmentsEnabled === TRUE)
    {
      $departments = $container->addCheckboxList('departments', NULL, $this->departmentsList);
      $departments->setDefaultValue($this->departments)
        ->getSeparatorPrototype()
        ->setName(NULL);
      $departments->getLabelPrototype()
        ->setClass('checkbox-inline');
    }

    if ($this->municipalitiesEnabled === TRUE || $this->departmentsEnabled === TRUE)
    {
      $districts = $container->addCheckboxList('districts', NULL, $this->districtsList);
      $districts->setDefaultValue($this->districts)
        ->getSeparatorPrototype()
        ->setName(NULL);
      $districts->getLabelPrototype()
        ->setClass('checkbox-inline');
    }

    $control = Html::el();

    if ($this->regionsEnabled === TRUE)
    {
      $regions->addRule(__CLASS__.'::validateOrganization', static::$validationMessages['organization'], [$regions, $municipalities, $departments]);

      $control->addHtml(Html::el('p', Html::el('small', Html::el('strong', 'Kraj')))->class('form-control-static'))
        ->addHtml($regions->getControl());
    }

    if ($this->municipalitiesEnabled === TRUE)
    {
      $municipalities->addRule(__CLASS__.'::validateOrganization', static::$validationMessages['organization'], [$regions, $municipalities, $departments])
        ->addRule(__CLASS__.'::validateDistrict', static::$validationMessages['district'], [$regions, $municipalities, $departments, $districts]);

      $control->addHtml(Html::el('p', Html::el('small', Html::el('strong', 'Obce')))->class('form-control-static'))
        ->addHtml($municipalities->getControl());
    }

    if ($this->departmentsEnabled === TRUE)
    {
      $departments->addRule(__CLASS__.'::validateOrganization', static::$validationMessages['organization'], [$regions, $municipalities, $departments])
        ->addRule(__CLASS__.'::validateDistrict', static::$validationMessages['district'], [$regions, $municipalities, $departments, $districts]);

      $control->addHtml(Html::el('p', Html::el('small', Html::el('strong', 'Příspěvkové organizace')))->class('form-control-static'))
        ->addHtml($departments->getControl());
    }

    if ($this->municipalitiesEnabled === TRUE || $this->departmentsEnabled === TRUE)
    {
      $control->addHtml(Html::el('hr'))
        ->addHtml(Html::el('p', Html::el('small', Html::el('strong', 'Okres')))->class('form-control-static'))
        ->addHtml($districts->getControl());
    }

    return $control;
  }

  public static function validateOrganization(IControl $control)
  {
    return count($control->regions) > 0 || count($control->municipalities) > 0 || count($control->departments) > 0;
  }

  public static function validateDistrict(IControl $control)
  {
    return (count($control->regions) > 0 && count($control->municipalities) === 0 && count($control->departments) === 0)
      || count($control->districts) > 0;
  }
@radekdostal

This comment has been minimized.

Copy link
Contributor Author

@radekdostal radekdostal commented Mar 7, 2017

ping @dg

@radekdostal

This comment has been minimized.

Copy link
Contributor Author

@radekdostal radekdostal commented Mar 7, 2017

IE console throws "Nedostatek místa v zásobníku" on this line.

@JanTvrdik

This comment has been minimized.

Copy link
Contributor

@JanTvrdik JanTvrdik commented Mar 7, 2017

@dg This seems important.

@radekdostal Do you know how to fix this?

@radekdostal

This comment has been minimized.

Copy link
Contributor Author

@radekdostal radekdostal commented Mar 7, 2017

Nette.expandRuleArgument is the problematic function. If I replace its implementation with version from 2.3, then everything is OK and JavaScript validation passes.

@radekdostal

This comment has been minimized.

Copy link
Contributor Author

@radekdostal radekdostal commented Mar 7, 2017

Just delete Nette.validateControl() call on this line and the problem is solved. But I don't know, if this change doesn't affect anything else. I use netteForms.js 2.4 on many projects without problems, I don't know, why on CheckboxLists is this deadlock: validateControl() -> validateRule() -> expandRuleArguments() -> validateControl()...

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Mar 7, 2017

Thanks for accurate issue report. Unfortunately I don't have time to solve it now…

@radekdostal

This comment has been minimized.

Copy link
Contributor Author

@radekdostal radekdostal commented Mar 7, 2017

This commit 8f27363 changed the original behavior.

@dg dg closed this in f4bb922 Mar 29, 2017
dg added a commit that referenced this issue Sep 29, 2019
…eventFiltering' workaround [Closes #161][Closes #143]

should be better solution than 94c47d5
dg added a commit that referenced this issue Sep 30, 2019
…eventFiltering' workaround [Closes #161][Closes #143]

should be better solution than 94c47d5
dg added a commit that referenced this issue Oct 1, 2019
…validateRule() [Closes #161][Closes #143]

should be better solution than 94c47d5
dg added a commit that referenced this issue Nov 18, 2019
…validateRule() [Closes #161][Closes #143]

should be better solution than 94c47d5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.