Field with readonly and default field not saving #3667
Replies: 3 comments
-
|
I got the same thing. I want the field to be read-only with a default value for some users, but admins are allowed to change the value. |
Beta Was this translation helpful? Give feedback.
-
|
I ran into this just now and was able to get around it with a hacky way (which seems like an old way of making fields read-only) of just adding the read-only attribute to the select (in my case) field: Select::make('field name')
->withMeta(['extraAttributes' => ['readonly' => true]])instead of Select::make('field name')
->readonly() |
Beta Was this translation helpful? Give feedback.
-
|
You can always override Nova behavior from Laravel Model Observers using events, if you require more information, I can help you with more code. https://laravel.com/docs/9.x/eloquent#observers But in general, this has worked for me without any issues to give you an idea on different approach perhaps, try to replicate and let us know: (Nova 4), but in general, observers can accomplish what you are looking for. If you can also provide a code that you want to work or algorithm, I can help you adjust it to make it work the way you wanted originally, there are many ways to do things in Nova or override Nova behavior, including making your own custom field or tool. In observers, you can check:
Or you can simply set the default value in MYSQL for the column in general, lots of options to go around nova |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there.
I had to open a new discussion with the same title as #3630 because that one was immediately closed.
I strongly disagree with the conclusion. Why a read-only field won't be saved??
Is that REALLY the expected behavior?
In my case, I need to show in a create form that the field will be saved with that specific value, and it cannot be edited.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions