diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 41d01a6e3b3..98a420e0c72 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -154,6 +154,7 @@ | */ + 'arr_fieldtype' => 'This is invalid.', 'code_fieldtype_rulers' => 'This is invalid.', 'date_fieldtype_date_required' => 'Date is required.', 'date_fieldtype_end_date_invalid' => 'Not a valid end date.', diff --git a/src/Fieldtypes/Arr.php b/src/Fieldtypes/Arr.php index 6ec5314463a..97474c3d0f4 100644 --- a/src/Fieldtypes/Arr.php +++ b/src/Fieldtypes/Arr.php @@ -2,6 +2,7 @@ namespace Statamic\Fieldtypes; +use Closure; use Statamic\Facades\GraphQL; use Statamic\Fields\Fieldtype; use Statamic\GraphQL\Types\ArrayType; @@ -81,4 +82,23 @@ public function toGqlType() { return GraphQL::type(ArrayType::NAME); } + + public function rules(): array + { + if ($this->isKeyed()) { + return []; + } + + return [function ($handle, $value, Closure $fail) { + $values = collect($value); + + if ($values->has('null')) { + $fail('statamic::validation.arr_fieldtype')->translate(); + } + + if ($values->count() !== $values->reject(fn ($v) => is_null($v))->count()) { + $fail('statamic::validation.arr_fieldtype')->translate(); + } + }]; + } }