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

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

Open
mskocik opened this issue Nov 21, 2024 · 0 comments

Comments

@mskocik
Copy link

mskocik commented Nov 21, 2024

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; 
			}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant