CheckboxList options set some value to checked
How can I set some value to checked?
41 Replies
you just need to return true or false in the values you want
you scroll through the array and the values you need return true
key value? But how can I set Label, value and the checkbox status?
try to use $state
in you function
Could you give me an example? I can understand the state and the return value
return [
'not_1' => 'All notification',
'not_2' => 'Some notification',
'not_e' => 'No notification',
];
return need to looke like this, otherwise it gives me an error
for example the state will fetch the value of the checkbox if I'm not in error
let me check
if the $notification->not_1 = true I need to set not_1 return value to true
some how 🙂
oh, wait is acheckboxlist, so it might be different than what I'm thinking
yes it's a list
I get the userId and some other Id - whit these id's I query the notifications - check the values and set the checkboxes
I read all the documentations bot not fund anything
I'll look for something to see if it helps
🙏
What values you want the checked to have and what is the condition to handle those values?
if ($notification->not_1) is true than I would like to return options [not_1] value set false ot true
CheckboxList::make('notifications')
->options(function (callable $get) {
$userId = $get('userId');
$powerPlantId = $get('power_plant_id');
$notifications = UserPowerPlant::where('user_id', $userId)->where('power_plant_id', $powerPlantId)->get();
return [
'not_1' => 'All notification',
'not_2' => 'Some notification',
'not_e' => 'No notification',
];
})->dehydrated(false),
my return contains 3 value
and those values needed to checked or not
If in your model you have the column casted as boolean all you need to do is 'checked' => $row->column_name
but where should I set the checked value?
options need to return with a simple array (key=> value) pair
Do you have a column for each option on your db table? Can you show a var dump of your $row somehow?
Yes of course just a sec
[2023-08-07 20:21:32] local.INFO: [{
"active_schedule_notification":false,
"active_billing_notification":true,
"active_datasheet_notification":false,
"active_billing_sample_notification":false,
...
}]
this a a row from nitifications
and every row has a label too
And where do you get the info for not_1, not_2, not_3
?
not_1, not_2 was just an example
"active_schedule_notification":false,
"active_billing_notification":true,
"active_datasheet_notification":false,
"active_billing_sample_notification":false,
is the real value
Oh I see. Gotcha... Let me see if I can come up with something
🙏
would you like to set default on the CreatePage?
?
Yup, this is what I was getting to
if it worked, mark the topic as solved please
It's not my post ahaha
ahh sorry 😅
It's not working - and only in options (callable) I know which should checked
I don't think that you can achieve that with a checkboxlist tbh... The options method doesn't handle the checked status, only value and label
hm - is it impossible? hmmm why? I think is not a big thing ...but yeah - I can't find anything 😦
default(true) isnt work too
Impossible? Don't know I'm not a filament dev xD it may not be a big thing but you have to take in consideration the limitations of the package you're using
Default values don’t work with checkbox list. Try dehydrating the field with your default values you want applied.
could you give me an example? here is my code:
Even if I put a dummy checbox - default vallue true dont work
These components working only with the Model Value?
Look up “dehydrateStateUsing()” in the Filament docs. I honestly don’t know what you are trying to do in the CheckboxList. You arent doing anything with the callable gets and sets…
Are you using the form builder or is this in a resource?
in a resource table function
I have a select which is reactive - if the user change the select values in the checkbox list de values need to be checked or not depend on the selected values
in the select list there are companyies and avery companies has a different nofifications - which I tried to set with a Checkbox list
Yeah I don’t think you can call the state of another field within the options array of a CheckboxList
so i cannot able to set the CheckBoxList values? 😦
I mean usually when you are doing things with dependent fields you only set a Field’s value not the Field’s options array. There may be a way but I couldn’t tell you right now.
Hi, are you solve this??
Sadly no 😦
This works for me: