You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Filled validation in custom Nette\Forms\Control instance #346
I have a custom form control implementing Nette\Forms\Control interface.
I want to add a common rule to check if that control is filled. Sadly, the default implementation delegates to the static Validator class that requires a BaseControl subtype.
I worked around this by providing custom rules that override the filled check:
class CustomControlRules extends Rules
{
publicstaticfunctionvalidateRule(Rule$rule): bool
{
if ($rule->validator === Form::Filled) {
$control = $rule->control;
if (!$controlinstanceof \MyCustomImplementation) {
thrownewInvalidStateException();
}
return$control->isFilled();
} else {
returnparent::validateRule($rule);
}
}
}
But, this is getting forbidden by the recent (Forms 3.2) changes that are making the Rules class final.
The simple solution is to remove the final once again, but since I got to report this, I'd ask you to consider some proper LSP solution -> ideally moving the required methods to the interface.
Add isFilled() to Control but commented out (not a BC break, at least for now), add use method_exists
Add ValidatedControl interface and implement in BaseControl
a. add there just validateFilled & validateMinMax (to extract this datetime logic)
b. add there more
Activity
dg commentedon Nov 25, 2025
Yeah, feel free to suggest some proper solutions.
hrach commentedon Nov 29, 2025
Which solution do you prefer?
a. add there just validateFilled & validateMinMax (to extract this datetime logic)
b. add there more
hrach commentedon Nov 29, 2025
Another option implemented in #347.
hrach commentedon Feb 20, 2026
@dg any opinion on this? thx.
hrach commentedon Apr 30, 2026
@dg gentle reminder
Validator: rules Filled, Blank and Valid accept any Control implement…
Validator: rules Filled, Blank and Valid accept any Control implement…
Validator: rules Filled, Blank and Valid accept any Control implement…
Validator: rules Filled, Blank and Valid accept any Control implement…
Validator: rules Filled, Blank and Valid accept any Control implement…
Validator: rules Filled, Blank and Valid accept any Control implement…