Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#1714 closed enhancement (wontfix)

[patch] add "readonly" attribute to form fields

Reported by: mir@… Owned by: adrian
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@… 9 years ago.
dummdidumm, here it comes ;-)
readonly_fields_v2.patch (24.1 KB) - added by SmileyChris 9 years ago.
Newer patch, building on mir@noris' patch
readonly_fields_v2.2.patch (25.4 KB) - added by SmileyChris 9 years ago.
spell check, small bug fix, and models integration

Download all attachments as: .zip

Change History (11)

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

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

Changed 9 years ago by mir@…

dummdidumm, here it comes ;-)

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

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

comment:3 Changed 9 years ago by anonymous

?

Changed 9 years ago by SmileyChris

Newer patch, building on mir@noris' patch

Changed 9 years ago by SmileyChris

spell check, small bug fix, and models integration

comment:4 Changed 9 years ago by SmileyChris

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 9 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 8 years ago by mir@…

  • Resolution set to wontfix
  • Status changed from new to closed

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

comment:7 Changed 8 years ago by mir@…

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

comment:8 Changed 5 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