Skip to content

Commit 03e9ff8

Browse files
committed
handle validation strings
1 parent df34391 commit 03e9ff8

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/Forms/Fields/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function toFieldArray(): array
2727
'type' => 'text',
2828
'input_type' => 'email',
2929
'placeholder' => $this->config('placeholder'),
30-
'validate' => [...$this->config('validate', []), 'email'],
30+
'validate' => [...((array) $this->config('validate', [])), 'email'],
3131
...Arr::except($this->config(), ['type', 'input_type', 'placeholder', 'validate']),
3232
];
3333
}

src/Forms/Form.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ private function convertFieldsFromBlueprint(\Statamic\Fields\Blueprint $blueprin
9999
return [
100100
...$section,
101101
'fields' => collect($section['fields'] ?? [])->map(function (array $field): array {
102-
if (
103-
Arr::get($field, 'field.type') === 'text'
104-
&& in_array('email', Arr::get($field, 'field.validate') ?? [])
105-
) {
102+
$validate = Arr::get($field, 'field.validate');
103+
$validateRules = is_string($validate) ? explode('|', $validate) : ($validate ?? []);
104+
105+
if (Arr::get($field, 'field.type') === 'text' && in_array('email', $validateRules)) {
106106
Arr::set($field, 'field.type', 'email');
107107
Arr::pull($field, 'field.input_type');
108108

109-
$remainingValidationRules = collect(Arr::get($field, 'field.validate'))
109+
$remainingValidationRules = collect($validateRules)
110110
->reject(fn (string $validate): bool => $validate === 'email');
111111

112112
if ($remainingValidationRules->isEmpty()) {

0 commit comments

Comments
 (0)