Opened 9 years ago
Closed 9 years ago
#25078 closed New feature (fixed)
Support disabled form fields
Reported by: | Claude Paroz | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'd like to propose adding support for disabled form fields in Django.
If it were only a matter of adding widget attributes, like it's feasible with the readonly
attribute, it wouldn't need special treatment. However, the disabled
attribute is particular in that user agents are not transmitting their values when POSTing form data.
A typical use case is a ModelForm where you'd like to disable some fields while still displaying all values. So currently, if you simply add disabled
to the widget attributes, you'll have a problem: the form will clear the field as the value is not present in the data (and the field is not in excluded fields).
Change History (8)
comment:1 by , 9 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
comment:2 by , 9 years ago
Summary: | Support disabled fields → Support disabled form fields |
---|---|
Triage Stage: | Unreviewed → Accepted |
I'd suggest to write to the mailing list to get some ideas for this. An implementation that reduces the amount of admin-specific code needed for ModelAdmin.readonly_fields
might be interesting (#342 / [bcd9482a20]).
comment:3 by , 9 years ago
ModelAdmin.readonly_fields
has chosen another route, that is displaying the value of the field instead of displaying a disabled form widget containing the value. I can write to the mailing list, but I'm not sure about what sort of ideas I would ask for.
comment:4 by , 9 years ago
Do you prefer or require disabled form widgets as opposed to displaying the values? Just curious.
comment:5 by , 9 years ago
Displaying a value is triggering a whole different machinery, as the readonly_fields
admin patch shows. I think what we address in this issue is a lot simpler as we simply rely on a HTML attribute of the widget. I think that displaying the disabled form widget makes sense as we are still in the context of displaying a form, but for whatever reason, some field is not editable by the current user.
comment:6 by , 9 years ago
Needs documentation: | unset |
---|
comment:7 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
POC pull request: https://github.com/django/django/pull/4958