Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#2926 closed enhancement (wontfix)

[patch] Custom FormField attributes

Reported by: Winston Lee <lee.winston@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: 0.95
Severity: normal Keywords: FormField attributes
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

FormField objects don't allow users to add their own custom attributes. Modified the abstract FormField class to also require the attribute_dict property. This property allows users to define their own attributes to render. For XHTML compliance, output is property="value". Therefore, if you want readonly attribute it'll have to output as readonly="readonly":

  { 'readonly':'readonly' }

Usage example:

attributes = {
  'onclick':'javascript:alert(\'running\');',
  'tabindex':'1',
  'title':'This is a title!',
}

self.fields = (
  forms.TextField(field_name="fieldName", is_required=False, length=10, attribute_dict=attributes),
  forms.TextField(field_name="otherField", is_required=False, length=10)
)

Shouldn't break your existing manipulators.

Attachments (2)

django_forms_attributes.diff (24.6 KB ) - added by Winston Lee <lee.winston@…> 17 years ago.
Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.
django_forms_attributes.2.diff (24.6 KB ) - added by Winston Lee <lee.winston@…> 17 years ago.
Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.

Download all attachments as: .zip

Change History (6)

by Winston Lee <lee.winston@…>, 17 years ago

Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.

by Winston Lee <lee.winston@…>, 17 years ago

Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.

comment:1 by Winston Lee <lee.winston@…>, 17 years ago

Couldn't override the previous patch. django_forms_attributes.2.diff fixes a bug in TimeField class.

comment:2 by Bastian Kleineidam <calvin@…>, 17 years ago

Double quotes in attribute values should be escaped with backslash, something like this:

v = v.replace('"', '\\"')

comment:3 by Jacob, 17 years ago

Resolution: wontfix
Status: newclosed

Since the forms system is being rewritten, I'm marking this WONTFIX (even though it *will* be fixed, just not in the current incarnation <g>).

comment:4 by (none), 17 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

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