From 4967a602ab6cfd2cf4f3f21de9723df88c6a2514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vodi=C4=8Dka?= Date: Wed, 29 May 2024 10:23:25 +0200 Subject: [PATCH 1/4] float --- src/Container.php | 10 ++++++++++ src/Form.php | 25 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Container.php b/src/Container.php index 4cfebd5..869ee21 100644 --- a/src/Container.php +++ b/src/Container.php @@ -81,6 +81,16 @@ public function addText(string $name, $label = null, ?int $cols = null, ?int $ma } + public function addFloat(string $name, $label = null): Control\TextInput + { + return $this[$name] = (new Control\TextInput($label)) + ->setNullable() + ->setHtmlType('number') + ->setHtmlAttribute('step', 'any') + ->addRule(self::Float); + } + + public function addAutocomplete(string $name, $label = null, ?int $maxLength = null, ?array $itemArray = []): Control\AutocompleteInput { return $this[$name] = (new Control\AutocompleteInput($label, $maxLength, items: $itemArray ?? [])) diff --git a/src/Form.php b/src/Form.php index 3ec8bed..78f4661 100644 --- a/src/Form.php +++ b/src/Form.php @@ -7,14 +7,15 @@ use Nette\Forms\Controls\DateTimeControl; use Nette\Utils\DateTime; use Nette\Utils\Html; +use Nette\Application\UI\Form; -class Form extends \Nette\Application\UI\Form +class Form extends Form { /** @deprecated use Form::GreaterEqual */ - public const GREATER_EQUAL = \Nette\Application\UI\Form::MIN; + public const GREATER_EQUAL = Form::MIN; /** @deprecated use Form::LessEqual */ - public const LESS_EQUAL = \Nette\Application\UI\Form::MAX; + public const LESS_EQUAL = Form::MAX; /** @deprecated use Form::Greater */ public const GREATER = '\ModulIS\Form\FormValidator::greater'; @@ -31,9 +32,9 @@ class Form extends \Nette\Application\UI\Form /** @deprecated use Form::validateIC */ public const VALIDATE_IC = 'ModulIS\Form\FormValidator::validateIC'; - public const GreaterEqual = \Nette\Application\UI\Form::MIN; + public const GreaterEqual = Form::MIN; - public const LessEqual = \Nette\Application\UI\Form::MAX; + public const LessEqual = Form::MAX; public const Greater = '\ModulIS\Form\FormValidator::greater'; @@ -275,6 +276,16 @@ public function addText(string $name, $label = null, ?int $cols = null, ?int $ma } + public function addFloat(string $name, $label = null): Control\TextInput + { + return $this[$name] = (new Control\TextInput($label)) + ->setNullable() + ->setHtmlType('number') + ->setHtmlAttribute('step', 'any') + ->addRule(self::Float); + } + + public function addAutocomplete(string $name, $label = null, ?int $maxLength = null, ?array $itemArray = []): Control\AutocompleteInput { return $this[$name] = (new Control\AutocompleteInput($label, $maxLength, items: $itemArray ?? [])) @@ -329,7 +340,7 @@ public function addEmail(string $name, $label = null): Control\TextInput { return $this[$name] = (new Control\TextInput($label)) ->setRequired(false) - ->addRule(self::EMAIL); + ->addRule(self::Email); } @@ -338,7 +349,7 @@ public function addInteger(string $name, $label = null): Control\TextInput return $this[$name] = (new Control\TextInput($label)) ->setNullable() ->setRequired(false) - ->addRule(self::INTEGER); + ->addRule(self::Integer); } From e4d1fb836b4c9885335a3e398e920da295d0a176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vodi=C4=8Dka?= Date: Wed, 29 May 2024 10:37:02 +0200 Subject: [PATCH 2/4] form use --- src/Form.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Form.php b/src/Form.php index 78f4661..f728dfb 100644 --- a/src/Form.php +++ b/src/Form.php @@ -7,15 +7,15 @@ use Nette\Forms\Controls\DateTimeControl; use Nette\Utils\DateTime; use Nette\Utils\Html; -use Nette\Application\UI\Form; +use Nette\Application\UI\Form as UIForm; -class Form extends Form +class Form extends UIForm { /** @deprecated use Form::GreaterEqual */ - public const GREATER_EQUAL = Form::MIN; + public const GREATER_EQUAL = UIForm::MIN; /** @deprecated use Form::LessEqual */ - public const LESS_EQUAL = Form::MAX; + public const LESS_EQUAL = UIForm::MAX; /** @deprecated use Form::Greater */ public const GREATER = '\ModulIS\Form\FormValidator::greater'; @@ -32,9 +32,9 @@ class Form extends Form /** @deprecated use Form::validateIC */ public const VALIDATE_IC = 'ModulIS\Form\FormValidator::validateIC'; - public const GreaterEqual = Form::MIN; + public const GreaterEqual = UIForm::MIN; - public const LessEqual = Form::MAX; + public const LessEqual = UIForm::MAX; public const Greater = '\ModulIS\Form\FormValidator::greater'; From 07a4312ba99aa75797082a72e285435e832fe14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vodi=C4=8Dka?= Date: Wed, 29 May 2024 10:40:05 +0200 Subject: [PATCH 3/4] phpstan --- src/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Container.php b/src/Container.php index 869ee21..87db818 100644 --- a/src/Container.php +++ b/src/Container.php @@ -87,7 +87,7 @@ public function addFloat(string $name, $label = null): Control\TextInput ->setNullable() ->setHtmlType('number') ->setHtmlAttribute('step', 'any') - ->addRule(self::Float); + ->addRule(Form::Float); } From 5f934b4f9db1969b9c8ee6f41988b3d660e0a54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vodi=C4=8Dka?= Date: Wed, 29 May 2024 10:42:03 +0200 Subject: [PATCH 4/4] cs --- src/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form.php b/src/Form.php index f728dfb..456088a 100644 --- a/src/Form.php +++ b/src/Form.php @@ -4,10 +4,10 @@ namespace ModulIS\Form; +use Nette\Application\UI\Form as UIForm; use Nette\Forms\Controls\DateTimeControl; use Nette\Utils\DateTime; use Nette\Utils\Html; -use Nette\Application\UI\Form as UIForm; class Form extends UIForm {