Select Disable when published
Hello friends, I have a question, how can I disable a field in select when it is already published? Thanks
19 Replies
Can you be more specific? You're already using
disableOptionWhen()
. Is this not what you're trying to achieve?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
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
is, what you are seeking for, because the value will be null
, when brand_id
is not set.What do you mean by "when the field is published"?
when the field exist on table
filled($record?->brand_id)
ok it worked but it doesn't do what you intended
continues to allow creating repeated fields
- 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 tablethe code does exactly that.
When the field is already in the table, it does not allow selecting in select
oh, you mean not allow select a brand more than once?
Hello, its the same of https://discord.com/channels/883083792112300104/1166392498579570739
oh,
we want the user to not be able to create a record with the exact same "selects" of existing ones
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
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