Separate validation for keys & values for key-value fields

Hi all Is there a way to apply separate validation rules for keys and values when using the key-value field? (as rows are added).
2 Replies
Patrick Boivin
Patrick Boivin15mo ago
Something like this should work:
->rule(
fn () => function (string $attribute, array $value, Closure $fail) {
foreach ($value as $itemKey => $itemValue) {
if (! is_valid_item_key($itemKey)) {
$fail("$itemKey is not a valid key");
}
}
}
),
->rule(
fn () => function (string $attribute, array $value, Closure $fail) {
foreach ($value as $itemKey => $itemValue) {
if (! is_valid_item_key($itemKey)) {
$fail("$itemKey is not a valid key");
}
}
}
),
Not sure if there's a simpler way
binaryfire
binaryfireOP15mo ago
@pboivin Thanks, will give that a shot!
Want results from more Discord servers?
Add your server