@@ -19,7 +19,7 @@ class Rules implements \IteratorAggregate
1919{
2020 use Nette \SmartObject;
2121
22- /** @var Rule|false| null */
22+ /** @var Rule|null */
2323 private $ required ;
2424
2525 /** @var Rule[] */
@@ -51,7 +51,7 @@ public function setRequired($value = true)
5151 if ($ value ) {
5252 $ this ->addRule (Form::REQUIRED , $ value === true ? null : $ value );
5353 } else {
54- $ this ->required = false ;
54+ $ this ->required = null ;
5555 }
5656 return $ this ;
5757 }
@@ -66,15 +66,6 @@ public function isRequired(): bool
6666 }
6767
6868
69- /**
70- * @internal
71- */
72- public function isOptional (): bool
73- {
74- return $ this ->required === false ;
75- }
76-
77-
7869 /**
7970 * Adds a validation rule for the current control.
8071 * @param callable|string $validator
@@ -217,7 +208,7 @@ public function getToggleStates(array $toggles = [], bool $success = true): arra
217208 */
218209 public function validate (bool $ emptyOptional = false ): bool
219210 {
220- $ emptyOptional = $ emptyOptional || $ this ->isOptional () && !$ this ->control ->isFilled ();
211+ $ emptyOptional = $ emptyOptional || ! $ this ->isRequired () && !$ this ->control ->isFilled ();
221212 foreach ($ this as $ rule ) {
222213 if (!$ rule ->branch && $ emptyOptional && $ rule ->validator !== Form::FILLED ) {
223214 continue ;
@@ -236,30 +227,6 @@ public function validate(bool $emptyOptional = false): bool
236227 }
237228
238229
239- /**
240- * @internal
241- */
242- public function check (): bool
243- {
244- if ($ this ->required !== null ) {
245- return false ;
246- }
247- foreach ($ this ->rules as $ rule ) {
248- if ($ rule ->control === $ this ->control && ($ rule ->validator === Form::FILLED || $ rule ->validator === Form::BLANK )) {
249- // ignore
250- } elseif ($ rule ->branch ) {
251- if ($ rule ->branch ->check () === true ) {
252- return true ;
253- }
254- } else {
255- trigger_error ("Missing setRequired(true | false) on field ' {$ rule ->control ->getName ()}' in form ' {$ rule ->control ->getForm ()->getName ()}'. " , E_USER_WARNING );
256- return true ;
257- }
258- }
259- return false ;
260- }
261-
262-
263230 /**
264231 * Clear all validation rules.
265232 */
0 commit comments