From 9b9995a316227ce7e32905a2c25b6b3ddff4e4a4 Mon Sep 17 00:00:00 2001 From: Thomas Pedersen Date: Thu, 7 Jul 2016 14:10:58 +0200 Subject: [PATCH] Bugfix - cant set min or max to 0 on numeric fields --- src/Fields/Base/NumericField.php | 6 +++--- tests/unit/FieldRenderCest.php | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Fields/Base/NumericField.php b/src/Fields/Base/NumericField.php index 3014b7a..9213c4b 100644 --- a/src/Fields/Base/NumericField.php +++ b/src/Fields/Base/NumericField.php @@ -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; } diff --git a/tests/unit/FieldRenderCest.php b/tests/unit/FieldRenderCest.php index 3321ca5..b548978 100644 --- a/tests/unit/FieldRenderCest.php +++ b/tests/unit/FieldRenderCest.php @@ -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; @@ -214,6 +213,12 @@ public function renderIntField(UnitTester $I) $field->max_value = 99; $I->assertSame('', $form->render($field)); + + $field->min_value = 0; + $field->max_value = 0; + $field->max_length = 0; + + $I->assertSame('', $form->render($field)); } public function renderFloatField(UnitTester $I) @@ -232,6 +237,12 @@ public function renderFloatField(UnitTester $I) $field->max_value = 99; $I->assertSame('', $form->render($field)); + + $field->min_value = 0; + $field->max_value = 0; + $field->max_length = 0; + + $I->assertSame('', $form->render($field)); } public function renderDateTimeField(UnitTester $I)