Skip to content

Commit

Permalink
Merge pull request #1 from PhlegmaticGuy/master
Browse files Browse the repository at this point in the history
Bugfix - cant set min or max to 0 on numeric fields
  • Loading branch information
mindplay-dk authored Jul 7, 2016
2 parents ee02a68 + 9b9995a commit f4f5b3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Fields/Base/NumericField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function renderInput(InputRenderer $renderer, InputModel $model, array $a
{
$defaults = [];

if ($this->max_length) {
if ($this->max_length !== null) {
$defaults['maxlength'] = $this->max_length;
}

if ($this->min_value) {
if ($this->min_value !== null) {
$defaults['min'] = $this->min_value;
}

if ($this->max_value) {
if ($this->max_value !== null) {
$defaults['max'] = $this->max_value;
}

Expand Down
13 changes: 12 additions & 1 deletion tests/unit/FieldRenderCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use mindplay\kissform\Fields\EmailField;
use mindplay\kissform\Fields\FloatField;
use mindplay\kissform\Fields\HiddenField;
use mindplay\kissform\Fields\InlineRadioGroup;
use mindplay\kissform\Fields\IntField;
use mindplay\kissform\Fields\PasswordField;
use mindplay\kissform\Fields\RadioGroup;
Expand Down Expand Up @@ -214,6 +213,12 @@ public function renderIntField(UnitTester $I)
$field->max_value = 99;

$I->assertSame('<input class="form-control" id="form-value" max="99" min="1" name="value" pattern="\d*" type="number"/>', $form->render($field));

$field->min_value = 0;
$field->max_value = 0;
$field->max_length = 0;

$I->assertSame('<input class="form-control" id="form-value" max="0" maxlength="0" min="0" name="value" pattern="\d*" type="number"/>', $form->render($field));
}

public function renderFloatField(UnitTester $I)
Expand All @@ -232,6 +237,12 @@ public function renderFloatField(UnitTester $I)
$field->max_value = 99;

$I->assertSame('<input class="form-control" id="form-value" max="99" min="1" name="value" pattern="\d*(\.(?=\d))?\d*" type="number"/>', $form->render($field));

$field->min_value = 0;
$field->max_value = 0;
$field->max_length = 0;

$I->assertSame('<input class="form-control" id="form-value" max="0" maxlength="0" min="0" name="value" pattern="\d*(\.(?=\d))?\d*" type="number"/>', $form->render($field));
}

public function renderDateTimeField(UnitTester $I)
Expand Down

0 comments on commit f4f5b3c

Please sign in to comment.