Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
getFieldByName now checks the list of actions in additon to just the …
Browse files Browse the repository at this point in the history
…field list
  • Loading branch information
travi committed Jul 3, 2014
1 parent 7ded5f2 commit f32c529
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions php/framework/src/travi/framework/components/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ public function mapErrorMessagesToFields($errors)
}
}

public function getFieldByName($fieldName)
{
$field = parent::getFieldByName($fieldName);

if (!isset($field)) {
/** @var Field $action */
foreach ($this->actions as $action) {
if (is_a($action, 'travi\\framework\\components\\Forms\\Field') && $fieldName === $action->getName()) {
$field = $action;
}
}
}

return $field;
}


public function hasErrors()
{
return !$this->isValid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function getFieldByName($fieldName)
) {
return $element;
} elseif (is_a($element, 'travi\\framework\\components\\Forms\\FormElementGroup')) {
/** @var FormElementGroup $element */
$field = $element->getFieldByName($fieldName);

if (!empty($field)) {
Expand Down
11 changes: 11 additions & 0 deletions php/framework/test/php/content/components/form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
travi\framework\components\Forms\inputs\DateInput,
travi\framework\components\Forms\inputs\TextInput;
use travi\framework\components\Forms\SubmitButton;
use travi\framework\view\objects\LinkView;

class FormTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -133,6 +134,16 @@ public function testValidationsArePassedInGetDependencies()
$this->assertSame($validations, $dependencies['validations'][$anyField->getName()]);
}

public function testThatActionInputCanBeRetievedByName()
{
$action = new SubmitButton();

$this->form->addAction(new LinkView('some text', 'some href'));
$this->form->addAction($action);

$this->assertSame($action, $this->form->getFieldByName('submit'));
}

public function testValidationErrorsMappedToProperFields()
{
$textName = 'test_text';
Expand Down

0 comments on commit f32c529

Please sign in to comment.