Skip to content

Commit

Permalink
Merge pull request #72 from modul-is/nette-forms
Browse files Browse the repository at this point in the history
Nette forms
  • Loading branch information
kravcik authored May 29, 2024
2 parents 7d3513e + 5f934b4 commit 2f09d55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(Form::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 ?? []))
Expand Down
25 changes: 18 additions & 7 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace ModulIS\Form;

use Nette\Application\UI\Form as UIForm;
use Nette\Forms\Controls\DateTimeControl;
use Nette\Utils\DateTime;
use Nette\Utils\Html;

class Form extends \Nette\Application\UI\Form
class Form extends UIForm
{
/** @deprecated use Form::GreaterEqual */
public const GREATER_EQUAL = \Nette\Application\UI\Form::MIN;
public const GREATER_EQUAL = UIForm::MIN;

/** @deprecated use Form::LessEqual */
public const LESS_EQUAL = \Nette\Application\UI\Form::MAX;
public const LESS_EQUAL = UIForm::MAX;

/** @deprecated use Form::Greater */
public const GREATER = '\ModulIS\Form\FormValidator::greater';
Expand All @@ -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 = UIForm::MIN;

public const LessEqual = \Nette\Application\UI\Form::MAX;
public const LessEqual = UIForm::MAX;

public const Greater = '\ModulIS\Form\FormValidator::greater';

Expand Down Expand Up @@ -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 ?? []))
Expand Down Expand Up @@ -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);
}


Expand All @@ -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);
}


Expand Down

0 comments on commit 2f09d55

Please sign in to comment.