Skip to content

Commit 296b8c8

Browse files
committed
added BaseControl::enableAutoOptionalMode()
1 parent b38ac91 commit 296b8c8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
6868
/** @var array user options */
6969
private $options = [];
7070

71+
/** @var bool */
72+
private static $autoOptional = FALSE;
73+
7174

7275
/**
7376
* @param string caption
@@ -80,6 +83,9 @@ public function __construct($caption = NULL)
8083
$this->label = Html::el('label');
8184
$this->caption = $caption;
8285
$this->rules = new Rules($this);
86+
if (self::$autoOptional) {
87+
$this->setRequired(FALSE);
88+
}
8389
$this->setValue(NULL);
8490
}
8591

@@ -527,6 +533,16 @@ public function cleanErrors()
527533
}
528534

529535

536+
/**
537+
* Globally enables new required/optional behavior.
538+
* This method will be deprecated in next version.
539+
*/
540+
public static function enableAutoOptionalMode()
541+
{
542+
self::$autoOptional = TRUE;
543+
}
544+
545+
530546
/********************* user data ****************d*g**/
531547

532548

0 commit comments

Comments
 (0)