BooleanGroup required validation not obeyed on action #5386
-
Description:Defining a Detailed steps to reproduce the issue on a fresh Nova installation:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
By default, given the above example, { "some": false }So, using just |
Beta Was this translation helpful? Give feedback.
-
|
Can you help explain to me why any value would be submitted when no checkbox was checked? |
Beta Was this translation helpful? Give feedback.
-
|
I should elaborate... this is a simplified example. In my case, the value of the checkbox was a string, however the action executed without anything being checked. |
Beta Was this translation helpful? Give feedback.
-
|
BooleanGroup::make('Permissions')->options([
'create' => 'Create',
'read' => 'Read',
'update' => 'Update',
'delete' => 'Delete',
])would return |
Beta Was this translation helpful? Give feedback.
-
|
@bkuhl The field starts with a valid state by its nature. The required validation in this case just checks the value is passed in the request. It sounds like you're trying to create a list of "are you sure you did this?" confirmations before running the action, but the user is allowed to ignore the list before submitting. Is that correct? If so, you could accomplish that like this: BooleanGroup::make('Everything looks correct?')->options([
'something' => 'Something',
'else' => 'Something Else',
])->rules([
function (string $attribute, mixed $value, Closure $fail) {
$options = json_decode($value, true);
$confirmedCount = count(array_filter($options, fn($val) => $val));
if ($confirmedCount !== count($options)) {
$fail('Nope, ya gotta check everything!');
}
}
]), |
Beta Was this translation helpful? Give feedback.
-
|
Ok, this all makes a lot more sense now, thank you. I'm actually just looking to have checkboxes for each relation to perform the action with. |
Beta Was this translation helpful? Give feedback.
@bkuhl The field starts with a valid state by its nature. The required validation in this case just checks the value is passed in the request.
It sounds like you're trying to create a list of "are you sure you did this?" confirmations before running the action, but the user is allowed to ignore the list before submitting. Is that correct? If so, you could accomplish that like this: