Skip to content

Commit

Permalink
controls: added option 'type' for distinguishing between them
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 11, 2016
1 parent fa3fe7f commit ffb3b6b
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Forms/Controls/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct($caption = NULL)
{
parent::__construct($caption);
$this->control->type = 'button';
$this->setOption('type', 'button');
}


Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct($label = NULL)
parent::__construct($label);
$this->control->type = 'checkbox';
$this->wrapper = Nette\Utils\Html::el();
$this->setOption('type', 'checkbox');
}


Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct($label = NULL, array $items = NULL)
$this->control->type = 'checkbox';
$this->container = Html::el();
$this->separator = Html::el('br');
$this->setOption('type', 'checkbox');
}


Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/HiddenField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct($persistentValue = NULL)
{
parent::__construct();
$this->control->type = 'hidden';
$this->setOption('type', 'hidden');
if ($persistentValue !== NULL) {
$this->unmonitor(Nette\Forms\Form::class);
$this->persistValue = TRUE;
Expand Down
7 changes: 7 additions & 0 deletions src/Forms/Controls/MultiSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class MultiSelectBox extends MultiChoiceControl
private $options = [];


public function __construct($label = NULL, array $items = NULL)
{
parent::__construct($label, $items);
$this->setOption('type', 'select');
}


/**
* Sets options and option groups from which to choose.
* @return self
Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/RadioList.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct($label = NULL, array $items = NULL)
$this->container = Html::el();
$this->separator = Html::el('br');
$this->itemLabel = Html::el();
$this->setOption('type', 'radio');
}


Expand Down
7 changes: 7 additions & 0 deletions src/Forms/Controls/SelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class SelectBox extends ChoiceControl
private $prompt = FALSE;


public function __construct($label = NULL, array $items = NULL)
{
parent::__construct($label, $items);
$this->setOption('type', 'select');
}


/**
* Sets first prompt item in select box.
* @param string
Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/TextArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct($label = NULL)
{
parent::__construct($label);
$this->control->setName('textarea');
$this->setOption('type', 'textarea');
}


Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct($label = NULL, $maxLength = NULL)
parent::__construct($label);
$this->control->type = 'text';
$this->control->maxlength = $maxLength;
$this->setOption('type', 'text');
}


Expand Down
1 change: 1 addition & 0 deletions src/Forms/Controls/UploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct($label = NULL, $multiple = FALSE)
parent::__construct($label);
$this->control->type = 'file';
$this->control->multiple = (bool) $multiple;
$this->setOption('type', 'file');
}


Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.Button.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addButton('button');

Assert::same('button', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.Checkbox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addCheckbox('on');

Assert::same('checkbox', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.CheckboxList.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addCheckboxList('list');

Assert::same('checkbox', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
1 change: 1 addition & 0 deletions tests/Forms/Controls.CsrfProtection.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Assert::same(['Security token did not match. Possible CSRF attack.'], $form->get
Assert::null($input->getOption('rendered'));
Assert::match('<input type="hidden" name="_token_" value="%S%">', (string) $input->getControl());
Assert::true($input->getOption('rendered'));
Assert::same('hidden', $input->getOption('type'));

$input->setValue(NULL);
Assert::false(CsrfProtection::validateCsrf($input));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.HiddenField.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addHidden('hidden');

Assert::same('hidden', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.ImageButton.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addImage('button');

Assert::same('button', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.MultiSelectBox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addMultiSelect('list');

Assert::same('select', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.RadioList.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addRadioList('list');

Assert::same('radio', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.SelectBox.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addSelect('list');

Assert::same('select', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.TextArea.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addTextArea('text');

Assert::same('textarea', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.TextInput.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addText('text');

Assert::same('text', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms/Controls.UploadControl.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ test(function () { // rendering options
$form = new Form;
$input = $form->addUpload('file');

Assert::same('file', $input->getOption('type'));

Assert::null($input->getOption('rendered'));
$input->getControl();
Assert::true($input->getOption('rendered'));
Expand Down

2 comments on commit ffb3b6b

@chemix
Copy link
Member

@chemix chemix commented on ffb3b6b Jan 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@f3l1x
Copy link
Member

@f3l1x f3l1x commented on ffb3b6b Jan 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.