F
Filament13mo 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
ChesterS13mo ago
Can you be more specific? You're already using disableOptionWhen() . Is this not what you're trying to achieve?
Xiquita
XiquitaOP13mo 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
johny713mo 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 Koch13mo ago
What do you mean by "when the field is published"?
Xiquita
XiquitaOP13mo ago
when the field exist on table
Saade
Saade13mo ago
->disabled(fn ($record) => filled($record?->brand_id))
->disabled(fn ($record) => filled($record?->brand_id))
Xiquita
XiquitaOP13mo ago
No description
Saade
Saade13mo ago
filled($record?->brand_id)
Xiquita
XiquitaOP13mo ago
ok it worked but it doesn't do what you intended continues to allow creating repeated fields
Saade
Saade13mo 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
XiquitaOP13mo ago
When the field is already in the table, it does not allow selecting in select
Xiquita
XiquitaOP13mo ago
No description
Saade
Saade13mo ago
oh, you mean not allow select a brand more than once?
Saade
Saade13mo ago
oh,
Gush
Gush13mo ago
we want the user to not be able to create a record with the exact same "selects" of existing ones
Dennis Koch
Dennis Koch13mo 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
Saade13mo 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