Skip to content

Rules defined after usage of BaseControl::addFilter() method are dropped and not renderered in HTML #341

Open
@mskocik

Description

@mskocik

Version: 3.2.2 (still present in master)

Bug Description

If addFilter() method is used BEFORE other rules, they are dropped and passed to HTML. Even documentation states that:

The filter is included between the validation rules and conditions and therefore depends on the order of the methods, i.e. the filter and the rule are called in the same order as is the order of the addFilter() and addRule() methods.

Steps To Reproduce

Nette fiddle ilustrating the problem.

Expected Behavior

All rules should be exported.

Possible Solution

Fix Nette\Forms\Helpers to NOT to exit whole foreach loop, when rule is not exportable.

namespace Nette\Forms;

use Nette;
use Nette\Utils\Html;
use Nette\Utils\Image;
use Nette\Utils\Strings;


/**
 * Forms helpers.
 */
final class Helpers

	public static function exportRules(Rules $rules): array
	{
		$payload = [];
		foreach ($rules as $rule) {
			if (!$rule->canExport()) {
				if ($rule->branch) {
					continue;
				}
				/** 
				 * 👇 this is the problem, when replaced
				 * by continue; seems to works, but I am not sure 
				 * it doesn't break something else
				 */ 
				break; 
			}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions