Added support for custom form field options validation with validate: options: key|ignore

This commit is contained in:
Matias Griese
2021-10-07 14:00:17 +03:00
parent 60fd4ec516
commit be136d3ce4
2 changed files with 11 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
* Added method `Pages::referrerRoute()` to get the referrer route and language
* Added true unique `Utils::uniqueId()` / `{{ unique_id() }}` utilities with length, prefix, and suffix support
* Added `UserObject::isMyself()` method to check if flex user is currently logged in
* Added support for custom form field options validation with `validate: options: key|ignore`
2. [](#improved)
* Replaced GPL `SVG-Sanitizer` with MIT licensed `DOM-Sanitizer`
* `Uri::referrer()` now accepts third parameter, if set to `true`, it returns route without base or language code [#3411](https://github.com/getgrav/grav/issues/3411)

View File

@@ -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') {