v2-hub
v2-hub copied to clipboard
Regex as validation rule in CP
doesn't work when pipes are used. Only if they are written direct in the yaml inside quotation marks.
Did you escape the pipes?
We need to allow for this by using an array format. The Laravel docs say this might happen and to use an array.
This can be fixed with a simple patch:
diff --git statamic/core/CP/Fieldset.php statamic/core/CP/Fieldset.php
index f8aa593..bf9a474 100644
--- statamic/core/CP/Fieldset.php
+++ statamic/core/CP/Fieldset.php
@@ -639,7 +639,15 @@ class Fieldset implements FieldsetContract
return array_merge($this->preProcessField($config), [
'display' => $this->getDisplayText($name, $config),
'instructions' => $this->getInstructionsText($name, $config),
- 'required' => Str::contains(array_get($config, 'validate'), 'required'),
+ 'required' => tap(array_get($config, 'validate'), function (&$rules) {
+ if (is_string($rules)) {
+ $rules = explode('|', $rules);
+ }
+
+ $rules = !collect($rules)->filter(function ($rule) {
+ return is_string($rule) ? starts_with($rule, 'required') : false;
+ })->isEmpty();
+ }),
]);
})->all();
}