#2926 closed enhancement (wontfix)
[patch] Custom FormField attributes
Reported by: | 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)
Change History (6)
by , 18 years ago
Attachment: | django_forms_attributes.diff added |
---|
by , 18 years ago
Attachment: | django_forms_attributes.2.diff added |
---|
Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.
comment:1 by , 18 years ago
Couldn't override the previous patch. django_forms_attributes.2.diff fixes a bug in TimeField class.
comment:2 by , 18 years ago
Double quotes in attribute values should be escaped with backslash, something like this:
v = v.replace('"', '\\"')
comment:3 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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>).
Patch for 0.95 to include custom attributes. Warning, not properly tested so you'll probably need to submit further patches.