Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2926 closed enhancement (wontfix)

[patch] Custom FormField attributes

Reported by: Winston Lee <lee.winston@…> Owned by: adrian
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: UI/UX:

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@…> 9 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@…> 9 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)

Changed 9 years ago by Winston Lee <lee.winston@…>

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

Changed 9 years ago by Winston Lee <lee.winston@…>

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

comment:1 Changed 9 years ago by Winston Lee <lee.winston@…>

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

comment:2 Changed 9 years ago by Bastian Kleineidam <calvin@…>

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

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

comment:3 Changed 9 years ago by jacob

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

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 Changed 8 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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