-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal/Suggestion/Enhancement] addField method 'view/update/create/all' (readonly and/or disabled fields) #234
Comments
What you mean is that when you edit you want to have some fields disabled? While there is currently no such feature you can create your own custom fields that do just that. Just add yourfield.blade.php to resources/views/vendor/backpack/crud/fields |
i think @giovannipds needs a field that is available only on the create process and, either if he makes a new field type just like you said, @indra1, he will need to add some sort of condition (if it's the edit page those fields get the 'disabled' attribute). |
@giovannipds I remembered there should be a feature for update/create/both Check Backpack\CRUD\PanelTraits\Fields for code. |
What I meant is, I would like to have some data(fields) displayed on the update page, without allowing the user to change those fields, just to see/read them (like a If I just mark it with Anyway, creating custom fields is awesome! Is there a way to check if I'm on the update or if I'm on the create page? As @AurelDragut mentioned. Thanks guys! |
@giovannipds To check if you're on edit page (there's where the update is triggered from): the edit page is effectively edit.blade.php if you want to check it out and if you are in the newly custom form just check if the field has a value isset($field['value']) |
Awesome! Thanks @indra1!! The proposal of this issue was to enable support of readonly fields on the update page somehow, but if you guys don't think that's relevant (because we can have custom fields anyway), please just feel free to close the issue. Regards. |
@giovannipds I think we should leave it open for now. It would be a good feature |
@giovannipds, this feature doesn't seem to be quite useful (you are the first one that i see talking about this feature), though you can see those "read only" fields at any time just by viewing instead of editing that model record. If you really wanna do something like this, the best way i think it is to add an additional attribute in the field definition for this feature and in blade templates of the fields that might need this add a condition if the added attribute has "true" value and if it meets the condition you can add to it a 'disabled=disabled' html attribute. something like:
|
@indra1 @AurelDragut I'm on up to you guys. I agree with @indra1. Thanks @AurelDragut. =) |
Another thing i can't test now it's a security issue: i think that if you show disabled fields in the form they might be modified by a web developer tool like Firebug, so on update the values might get changed beside that 'disabled' attribute...(i remember i tested something like this quite a time ago on a lesson about form validation). |
That's true, but if you remove the name of the field it should not work, but a smart person might still be able to bypass that easily. Let me get back to you on this. |
We've had a solution for this use case from day 1. $this->crud->addField([ // Text
'name' => 'title',
'label' => "Title",
'type' => 'text',
], 'create');
$this->crud->addField([ // Text
'name' => 'title',
'label' => "Title",
'type' => 'text',
'attributes' => ['readonly' => 'readonly'],
], 'update'); This will show a normal field on CREATE and a readonly field on UPDATE. Please note:
Cheers! P.S. I'll go ahead and close this issue so we don't clog the section. Feel free to open it again if you encounter problems or comment if you have follow-ups. |
@tabacitu Damnn! Never thought about that this way, I guess I was too concerned on not duplicating |
Googled for a read-only field approach and found this. Just wanted to go on record that @giovannipds isn't the only person who would like something built-in. In my case, it's an auto-generated field (think of it like a special token or key associated with the record) that I only want to show after creation, and never allow manually updating. Anyway, thanks! :) |
Hi @joshlewis , I think the $this->crud->addField([ // Text
'name' => 'title',
'label' => "Title",
'type' => 'text',
'attributes' => ['disabled' => 'disabled'],
], 'update'); |
Also googled for the same feature and ended up here. The 'disabled' and 'readonly' attributes ARE what I needed, so thanks! Perhaps a quick mention of these somewhere in the Field Types documentation would be appropriate? |
@SonicZentropy will do, but you can also edit it yourself and @tabacitu then reviews it. |
Are there any news on this topic? I would need to implement user access control at field level. "Invisible / Read-Only / Write" on a field, depending on a certain permission of the current user. The solution above 'attributes' => [disabled...... 'update') doesn't prevent simple post hacking. |
@axelzuzek No as far as I know, but if you want you could overwrite the store method and remove those fields from the request as needed for now. |
@indra1 thx, it works for me. for simple attributes it is enough to remove the "read-only" attribute from request to avoid overwriting with empty values ($request->remove("readonlyattributename"). For many2many relationships this seems not to be enough. In addition I had to set dynamically 'pivot' => false in the addField options. I think the syncPivot in the create and update traits should only be called if there are request parameters present? |
Here is an example for the archive:
|
Hello! I was playing with Backpack CRUD and apparently there's no way of showing fields in the administration panel without allowing edition, something like a readonly/disabled, am I wrong?!
If there really isn't, maybe the addField method can change to something like
'view/update/create/all'
, and if there's only view and not update, we can show the field with a readonly/disabled.Concerns? If I am wrong, please let me know.
The text was updated successfully, but these errors were encountered: