field disabled on the edit page and hidden on the create new record page
hi i would like to have this field disabled on the edit page and hidden on the create new record page
any idea how could i accomplish this ? thank you
Solution:Jump to solution
```php
return $form
->schema([
Forms\Components\TextInput::make('location')
->required()...
32 Replies
im using this when creating new record
i just want to show the user when editing but not be able to change it
->disabled(fn($context) => $context === ‘edit’)
->hiddenOn(‘create’)
Undefined constant "App\Filament\Resources‘create’"
Weird. So do the same thing as disabled.
->hidden(fn() => …)
my ide says Undefined constant '‘create’'
same for edit
Show the code.
Weird. Like I said try the same thing but use hidden instead of hiddenOn.
$context is injected into most field modifier callbacks so you should be able to check against it.
i get the same thing
That should be working.
its not
this is
idk how if its correct its generated by copilot
Then use that if it’s working but that’s all that context is doing under the hood.
yea that one is working
So use it.
thank you again for your time
👍
No worries. Surprised context isn’t working though.
maybe its something in my setup , does it work in your enviroment ?
It’s operation in v3 but supports context as a fallback for compatibility. https://filamentphp.com/docs/3.x/forms/advanced#injecting-the-current-form-operation
i see , well idk you know more than me 🙂
im just glad it works , thank you
if i can bug you a bit if you look at the code there i get the user_id i would like to get the name but using the user.name doesn't return anything
this is my resource model
it works for the table
Yea. Tables use dot syntax to eager load relationships. Forms don’t.
the only way i found is using select there
You could use a select or any of the layout components. They allow a relationship.
or is there a better way
All the layout components support relationships.
when you refer to layout components which ones are those exactly sorry
That’s a start.
thanks
well this works but is this the right way to use a fieldset
Solution
tweaked 😄
Totally fine.
A layout form component with ->relationship() is the same thing as a table column using the dot syntax.
Forms just can’t use the dot syntax for other reasons.
ok thanks much appreciated seeing things more clearly now 🙂