mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 12:06:40 +02:00
Added support for custom form field options validation with validate: options: key|ignore
This commit is contained in:
@@ -781,14 +781,22 @@ class Validation
|
||||
}
|
||||
|
||||
// If creating new values is allowed, no further checks are needed.
|
||||
if (!empty($field['selectize']['create'])) {
|
||||
$validateOptions = $field['validate']['options'] ?? null;
|
||||
if (!empty($field['selectize']['create']) || $validateOptions === 'ignore') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$options = $field['options'] ?? [];
|
||||
$use = $field['use'] ?? 'values';
|
||||
|
||||
if (empty($field['selectize']) || empty($field['multiple'])) {
|
||||
if ($validateOptions) {
|
||||
// Use custom options structure.
|
||||
foreach ($options as &$option) {
|
||||
$option = $option[$validateOptions] ?? null;
|
||||
}
|
||||
unset($option);
|
||||
$options = array_values($options);
|
||||
} elseif (empty($field['selectize']) || empty($field['multiple'])) {
|
||||
$options = array_keys($options);
|
||||
}
|
||||
if ($use === 'keys') {
|
||||
|
||||
Reference in New Issue
Block a user