Module version(s) affected
6.x, >= 5.1
Description
In version 5.0 merely used the list of valid values to determine what would be saved to the database.
Starting with version 5.1 it guesses the type of the first value of the valid values and further selects the values to be based based on the type of that first value.
I happened to have a list of valid values where the first value was an integer. As a result, string values would no longer save.
How to reproduce
Code
<?php
namespace App\Model;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\ListboxField;
class TestObject extends DataObject
{
private static $table_name = 'TestObject';
private static $db = [
'Values' => 'Text',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
// This order will cause the value ABC123 to be selectable but will be filtered out when saving because the first value is a numeric string, which causes the ListboxField to filter values as numeric strings.
$source = [
'123' => 'Numeric string',
'ABC123' => 'Alpha-numeric string',
];
// Case A: numeric-string first (this is the broken case)
$fields->push(
ListboxField::create(
'Values',
'Values (numeric string first)',
$source
)
);
return $fields;
}
}
Steps to recreate
- Add this DataObject to your project with an Admin.
- In the admin, select both values and save.
- Only the numerical value is saved.
NOTE: If the values have a string value first all the valid values will be saved.
Possible Solution
I would revert back to the behaviour in 5.0.
I tried to find the reason for the change of behaviour with no success. The change as introduced in commit e1d10a0 with the comment: "NEW ListboxField react field schema"
Additional Context
No response
Validations
PRs
Module version(s) affected
6.x, >= 5.1
Description
In version 5.0 merely used the list of valid values to determine what would be saved to the database.
Starting with version 5.1 it guesses the type of the first value of the valid values and further selects the values to be based based on the type of that first value.
I happened to have a list of valid values where the first value was an integer. As a result, string values would no longer save.
How to reproduce
Code
Steps to recreate
NOTE: If the values have a string value first all the valid values will be saved.
Possible Solution
I would revert back to the behaviour in 5.0.
I tried to find the reason for the change of behaviour with no success. The change as introduced in commit e1d10a0 with the comment: "NEW ListboxField react field schema"
Additional Context
No response
Validations
silverstripe/installer(with any code examples you've provided)PRs