Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31898 closed New feature (wontfix)

New Form Widget similar to Admin Read-only display

Reported by: David Owned by: nobody
Component: Forms Version: 3.1
Severity: Normal Keywords: forms widget
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The admin read-only option has been really helpful in displaying fields as text values. In standard forms it can be a pain to build a widget that would display the field value as text in the same way the admin does on either read_only fields or on all fields when the user only has view permission since 2.1.

My idea, would be to add a standard widget (perhaps PlainTextWidget) that would display the form field value in the same way that the admin renders it (as plain text, or in the case of ForeignKeys as the model label). This seems to come up more frequently and since the functionality is used through contrib.admin it would likely make sense to include it as more reusable code.

I'd take a stab at a PR, but tracking down how the admin generates the plain text widget is a little beyond me.

Change History (2)

comment:1 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed

Hi David. Thanks for the report.

I'm going to say wontfix here. This kind of thing is already possible using a Crispy Forms layout, and it'd be easy enough to add a custom widget to your own project.

Whilst the admin does it, in the end I'm not sure it's a pattern I'd recommend. Your form is ≈the gatekeeper to your application. Including the field only to then disable it is 😬 — what happends when you forget? Then cleaned_data has an unwanted item, and... If you don't want a field to be submitted, don't include it. Then use a template to render how you wish... (The aforementioned Crispy Forms layouts add a good deal of flexibility here.)

comment:2 by David, 4 years ago

Hi Carlton,

Fair enough, I hadn't thought of using crispy forms for that, I just figured the use case might come up often enough for people that it would be a handy widget. The way the admin accomplished the read only view is a pretty handy way to make a quick view only or print friendly version of a form. It's definitely going beyond the standard use for forms, but then admin does it too.

Thanks for taking a look anyway.

Note: See TracTickets for help on using tickets.
Back to Top