F
Filament14mo ago
Xiquita

Select Disable when published

Hello friends, I have a question, how can I disable a field in select when it is already published? Thanks
No description
19 Replies
ChesterS
ChesterS14mo ago
Can you be more specific? You're already using disableOptionWhen() . Is this not what you're trying to achieve?
Xiquita
XiquitaOP14mo ago
Yes, I'm using ->disableOptionWhen(fn (string $value): bool => $value === 'brand_id') but it's not doing what I want, what I want is that when the field is published it doesn't allow publish no more
johny7
johny714mo ago
Your condition says, the Select brand_id should be disabled, when it's own value is brand_id. I think, when you select an option from the relationship brands, you will get an integer ID of the brand, but never the value brand_id. So your condition will never match. Maybe
->disableOptionWhen(fn (string $value):bool => $value!==null),
->disableOptionWhen(fn (string $value):bool => $value!==null),
is, what you are seeking for, because the value will be null, when brand_id is not set.
Dennis Koch
Dennis Koch14mo ago
What do you mean by "when the field is published"?
Xiquita
XiquitaOP14mo ago
when the field exist on table
Saade
Saade14mo ago
->disabled(fn ($record) => filled($record?->brand_id))
->disabled(fn ($record) => filled($record?->brand_id))
Xiquita
XiquitaOP14mo ago
No description
Saade
Saade14mo ago
filled($record?->brand_id)
Xiquita
XiquitaOP14mo ago
ok it worked but it doesn't do what you intended continues to allow creating repeated fields
Saade
Saade14mo ago
- I want, what I want is that when the field is published it doesn't allow publish no more - What do you mean by "when the field is published"? - when the field exist on table
the code does exactly that.
Xiquita
XiquitaOP14mo ago
When the field is already in the table, it does not allow selecting in select
Xiquita
XiquitaOP14mo ago
No description
Saade
Saade14mo ago
oh, you mean not allow select a brand more than once?
Saade
Saade14mo ago
oh,
Gush
Gush14mo ago
we want the user to not be able to create a record with the exact same "selects" of existing ones
Dennis Koch
Dennis Koch14mo ago
This won't prevent them from selecting the value, though, but it should be applied nevertheless. If you don't want them to select existing items, just diff them with the records already in your DB. Shouldn't be too much of Laravel logic
Saade
Saade14mo ago
yeah, i kinda prefer allowing the user to select the item, then throw the validation explaining why he can't select that value, rather than not show the option et al as it looks like something is not working idk, personal preference i guess
Want results from more Discord servers?
Add your server