Skip to content

Commit 8b3a267

Browse files
committed
Changed empty function for choices field
1 parent 4c6d845 commit 8b3a267

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ContactForm extends Form
4141
{
4242
// Use this function to crossfields validation
4343
//
44-
// You can use $this->addError($message, $field) to add error messages to specific fields.
44+
// You can use $this->addError($message, $field_name) to add error messages to specific fields.
4545
// Or just throw a ValidationError Exception.
4646
}
4747
}

src/Fields/ChoiceField.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ public function setChoices(array $choices)
3333
$this->widget->setChoices($choices);
3434
}
3535

36+
public function isEmpty($value)
37+
{
38+
return empty($value) && $value != "0";
39+
}
40+
3641
public function toNative($value)
3742
{
38-
return !empty($value) ? (string) $value : '';
43+
return !$this->isEmpty($value) ? (string) $value : '';
3944
}
4045

4146
public function validate($value)
4247
{
4348
parent::validate($value);
4449

45-
if (empty($value) || !array_key_exists($value, $this->choices)) {
50+
if ($this->isEmpty($value) || !array_key_exists($value, $this->choices)) {
4651
$message = Formatter::format($this->error_messages['invalid'], array(
4752
'choice' => $value
4853
));

0 commit comments

Comments
 (0)