diff --git a/src/Fieldtypes/Lists.php b/src/Fieldtypes/Lists.php index e42dba1433a..9fac3224547 100644 --- a/src/Fieldtypes/Lists.php +++ b/src/Fieldtypes/Lists.php @@ -38,6 +38,10 @@ public function process($data) return collect($data)->reject(function ($item) { return in_array($item, [null, ''], true); + })->map(function ($item) { + return is_numeric($item) + ? (str_contains($item, '.') ? (float) $item : (int) $item) + : $item; })->values()->all(); } diff --git a/tests/Fieldtypes/ListTest.php b/tests/Fieldtypes/ListTest.php new file mode 100644 index 00000000000..e09d9a6e829 --- /dev/null +++ b/tests/Fieldtypes/ListTest.php @@ -0,0 +1,27 @@ +assertSame( + ['a', 2, 3, '4 and a half', 5.7, 8.3], + $this->field()->process(['a', '2', 3, '4 and a half', '5.7', 8.3]) + ); + } + + private function field($config = []) + { + $ft = new Lists; + + return $ft->setField(new Field('test', array_merge($config, ['type' => $ft->handle()]))); + } +}