diff --git a/administrator/components/com_fields/models/field.php b/administrator/components/com_fields/models/field.php index c2a8d5515a278..2c51d34e834ac 100644 --- a/administrator/components/com_fields/models/field.php +++ b/administrator/components/com_fields/models/field.php @@ -217,7 +217,7 @@ public function save($data) private function checkDefaultValue($data) { // Empty default values are correct - if (empty($data['default_value'])) + if (empty($data['default_value']) && $data['default_value'] !== '0') { return true; } diff --git a/libraries/src/Form/Rule/OptionsRule.php b/libraries/src/Form/Rule/OptionsRule.php index 39d8961859839..167aee47e8685 100644 --- a/libraries/src/Form/Rule/OptionsRule.php +++ b/libraries/src/Form/Rule/OptionsRule.php @@ -26,7 +26,7 @@ class OptionsRule extends FormRule * Method to test the value. * * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. - * @param mixed $value The form field value to validate. + * @param mixed $value The value to validate. * @param string $group The field name group control value. This acts as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". @@ -42,7 +42,10 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry // Check if the field is required. $required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); - if (!$required && empty($value)) + // Check if the value is empty. + $blank = empty($value) && $value !== '0' && $value !== 0 && $value !== 0.0; + + if (!$required && $blank) { return true; }