Skip to content

Commit fcd1885

Browse files
authored
Fix default Custom Field in some cases (#27618)
1 parent b90df84 commit fcd1885

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

administrator/components/com_fields/models/field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function save($data)
217217
private function checkDefaultValue($data)
218218
{
219219
// Empty default values are correct
220-
if (empty($data['default_value']))
220+
if (empty($data['default_value']) && $data['default_value'] !== '0')
221221
{
222222
return true;
223223
}

libraries/src/Form/Rule/OptionsRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class OptionsRule extends FormRule
2626
* Method to test the value.
2727
*
2828
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
29-
* @param mixed $value The form field value to validate.
29+
* @param mixed $value The value to validate.
3030
* @param string $group The field name group control value. This acts as an array container for the field.
3131
* For example if the field has name="foo" and the group value is set to "bar" then the
3232
* full field name would end up being "bar[foo]".
@@ -42,7 +42,10 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
4242
// Check if the field is required.
4343
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
4444

45-
if (!$required && empty($value))
45+
// Check if the value is empty.
46+
$blank = empty($value) && $value !== '0' && $value !== 0 && $value !== 0.0;
47+
48+
if (!$required && $blank)
4649
{
4750
return true;
4851
}

0 commit comments

Comments
 (0)