Opened 11 years ago

Closed 10 years ago

Last modified 7 years ago

#1714 closed enhancement (wontfix)

[patch] add "readonly" attribute to form fields

Reported by: mir@… Owned by: Adrian Holovaty
Component: Core (Other) Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I often have forms with readonly fields. This patch adds an "readonly" attribute to all form fields, and an optional parameter to all init methods. For some elements (select and checkbox) it actually uses the "disabled" attribute, but it's much nicer to use "readonly" in init() consistently.

Attachments (3)

readonly-fields.diff (20.4 KB) - added by mir@… 11 years ago.
dummdidumm, here it comes ;-)
readonly_fields_v2.patch (24.1 KB) - added by Chris Beaven 10 years ago.
Newer patch, building on mir@noris' patch
readonly_fields_v2.2.patch (25.4 KB) - added by Chris Beaven 10 years ago.
spell check, small bug fix, and models integration

Download all attachments as: .zip

Change History (11)

comment:1 Changed 11 years ago by Malcolm Tredinnick <malcolm@…>

Um ... this will work better if you attach the patch. :-)

Changed 11 years ago by mir@…

Attachment: readonly-fields.diff added

dummdidumm, here it comes ;-)

comment:2 Changed 11 years ago by Christopher Lenz <cmlenz@…>

I would love to see this applied as well :-)

comment:3 Changed 10 years ago by anonymous

?

Changed 10 years ago by Chris Beaven

Attachment: readonly_fields_v2.patch added

Newer patch, building on mir@noris' patch

Changed 10 years ago by Chris Beaven

Attachment: readonly_fields_v2.2.patch added

spell check, small bug fix, and models integration

comment:4 Changed 10 years ago by Chris Beaven

Just a small note on the models patch, there is no purpose for it if you're just using contrib.admin, because that hides fields which aren't editable.

I still think it's useful to pass is_readonly to a model's FormFields in case someone is doing something more low-level.

comment:5 Changed 10 years ago by mir@…

I still maintain this patch, but I'm tired of putting it here after each merge conflict. If you use this and want an up to date version, please contact me by email ;-)

comment:6 Changed 10 years ago by mir@…

Resolution: wontfix
Status: newclosed

I'm closing this since the old forms stuff is deprecated and new forms allow this in a more generic way.

comment:7 Changed 10 years ago by mir@…

  • I need a test ticket to see if the reporter is notified about responses -

comment:8 Changed 7 years ago by anonymous

override admin.ModelAdmin like

def formfield_for_dbfield(self, db_field, **kwargs):
    if db_field.name == readOnlyField:
        kwargs["widget"] = AdminTextInputWidget(attrs={"readonly":"readonly"})

    super(className, self).formfield_for_dbfield(db_field, **kwargs)
Note: See TracTickets for help on using tickets.
Back to Top