Open hdodov opened 5 years ago
Could you try if it works like that for you (without array keys)?
Kirby::plugin('me/plugin', [
'fields' => [
'myfield' => [
'validations' => [
// Allow custom validators...
function ($value) {
return $value === 'foobar';
},
// But also native ones.
'max',
'min'
]
]
]
]);
Nope, it throws an error:
Function name must be a string
It's why I added them as key-value pairs in my proposal.
As far as I've seen from native fields, they can specify
validations
and use any of the native validators (but not custom ones). However, it's likely that a custom field would require its own validation.My proposal is to turn the
validations
option in an associative array and allow developers to specify anonymous functions for validation. For example:Or perhaps add a new extension type,
fieldValidators
where you specify your validation functions, while thevalidations
option still accepts only the names.