Opened 18 years ago

Closed 17 years ago

Last modified 14 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: no UI/UX: no

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

Download all attachments as: .zip

Change History (11)

comment:1 by Malcolm Tredinnick <malcolm@…>, 18 years ago

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

by mir@…, 18 years ago

Attachment: readonly-fields.diff added

dummdidumm, here it comes ;-)

comment:2 by Christopher Lenz <cmlenz@…>, 18 years ago

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

comment:3 by anonymous, 18 years ago

?

by Chris Beaven, 18 years ago

Attachment: readonly_fields_v2.patch added

Newer patch, building on mir@noris' patch

by Chris Beaven, 18 years ago

Attachment: readonly_fields_v2.2.patch added

spell check, small bug fix, and models integration

comment:4 by Chris Beaven, 18 years ago

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 by mir@…, 17 years ago

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 by mir@…, 17 years ago

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 by mir@…, 17 years ago

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

comment:8 by anonymous, 14 years ago

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