Skip to content

Commit

Permalink
Merge pull request #3 from nathanjdunn/feature/number-method
Browse files Browse the repository at this point in the history
FormBuilder Number Method
  • Loading branch information
sdebacker authored Feb 18, 2019
2 parents 8eecae3 + 0bb5729 commit a711afa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/TypiCMS/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use TypiCMS\Form\Elements\FormOpen;
use TypiCMS\Form\Elements\Hidden;
use TypiCMS\Form\Elements\Label;
use TypiCMS\Form\Elements\Number;
use TypiCMS\Form\Elements\Password;
use TypiCMS\Form\Elements\RadioButton;
use TypiCMS\Form\Elements\Select;
Expand Down Expand Up @@ -79,6 +80,17 @@ public function text($name)
return $text;
}

public function number($name)
{
$number = new Number($name);

if (!is_null($value = $this->getValueFor($name))) {
$number->value($value);
}

return $number;
}

public function date($name)
{
$date = new Date($name);
Expand Down
10 changes: 10 additions & 0 deletions tests/BindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function testBindTextWithIntegerZero()
$this->assertEquals($expected, $result);
}

public function testBindNumber()
{
$object = $this->getStubObject();
$this->form->bind($object);

$expected = '<input type="number" name="number" value="0">';
$result = (string) $this->form->number('number');
$this->assertEquals($expected, $result);
}

public function testBindDate()
{
$object = $this->getStubObject();
Expand Down
11 changes: 11 additions & 0 deletions tests/FormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public function testTextBox()
$this->assertEquals($expected, $result);
}

public function testNumber()
{
$expected = '<input type="number" name="number">';
$result = (string) $this->form->number('number');
$this->assertEquals($expected, $result);

$expected = '<input type="number" name="age">';
$result = (string) $this->form->number('age');
$this->assertEquals($expected, $result);
}

public function testPassword()
{
$expected = '<input type="password" name="password">';
Expand Down

0 comments on commit a711afa

Please sign in to comment.