Opened 17 years ago
Closed 14 years ago
#6631 closed New feature (invalid)
Additional options for newforms
Description ¶
This ticket and patch try to add new options for inner class "Meta". It depends on #6630. It would fix #3512 and #3515.
All options are independent - it is no problem to accept only a subset.
error_class ¶
- default value - django.newforms.ErrorList
- replaces error_class argument from Form.init
- backward-incompatible - it breaks all forms with argument error_class
- I don't really care about this change (I have never use this argument), but it is consistent with the other options
formfield_for_formfield ¶
- default_value - lambda self, formfield: formfield
- function or method (it is normalized as a function) with two arguments - options and a formfield
- it should return a formfield
- it is called during the construction of base fields for the form
- it should be place for general customization and for javascript tricks
- I want to use it for javascript calendars
html_class_for_fields_with_errors ¶
- default_value - errors
- if it is not None, this option is added as an attribute to generated html (by BoundField.row_attrs) - only for fields with errors
- backward-incompatible - it could change generated html, but it could be reverted by setting to None
html_class_for_hidden_fields_row ¶
- default_value - hidden
- if it is not None, this option is added as an attribute to generated html (by Form.hidden_fields_html_output) - only for hidden row
- backward-incompatible - it could change generated html, but it could be reverted by setting to None
html_class_for_required_fields ¶
- default_value - required
- if it is not None, this option is added as an attribute to generated html (by BoundField.row_attrs) - only for required fields
- backward-incompatible - it could change generated html, but it could be reverted by setting to None
label_capitalization ¶
- default_value - True
- if it is True, first letter of labels are capitalized
- it solves a problem of translators - in models first letter of verbose_name should not be capitalized, but in forms first letter should be capitalized - so translator has to translate some words twice
- backward-incompatible - it could change generated html, but it could be reverted by setting to False
label_suffix ¶
- default value - :
- replaces label_suffix argument from Form.init
- backward-incompatible - it breaks all forms with argument label_suffix
- I don't really care about this change (I have never use this argument), but it is consistent with the other options
validation_order ¶
- default value - None
- it could be a list of field names for forms
- if it is None, it changes ordering of fields in validation
- it could be useful in situations where it is necessary to generate and validate forms in different order
Change History (11)
by , 17 years ago
Attachment: | 01-newforms-options.diff added |
---|
comment:1 by , 17 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
by , 17 years ago
Attachment: | 01-newforms-options.2.diff added |
---|
comment:2 by , 17 years ago
- Patch is based on the new patch from #6631 and depends on it.
- Option formfield_for_formfield is removed because it is too complex and not powerful enough.
- Some options are renamed to be shorter.
- Complete list of options - fieldsets, fields, exclude, model (only for ModelForm), error_class, error_row_class, hidden_row_class, label_capfirst, label_suffix, required_row_class, validation_order. (I am sure that native speakers could find better names.)
comment:3 by , 17 years ago
Keywords: | post10 added |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
Please bring this to django-developers, if possible after 1.0
by , 17 years ago
Attachment: | 01-forms-options.diff added |
---|
comment:4 by , 17 years ago
Changed to be compatible with trunk. Removed validation_order - it does not seemed to be useful. Added option use_field_row_class and method _field_row_class - for row html class based on field, it was the last missing information for styling of forms outputting with standard methods.
Added backward compatible versions of options:
- error_class: ErrorList preferred and backward-compatible
- error_row_class: 'error' preferred, None backward-compatible
- hidden_row_class: 'hidden' preferred and backward-compatible
- label_capfirst: True preferred, False backward-compatible
- label_suffix: ':' preferred and backward-compatible
- required_row_class: 'required' preferred, None backward-compatible
- use_field_row_class: True preferred, False backward-compatible
With last patch from #6630 and with backward-compatible versions of options, all tests pass. With preferred options forms has useful html classes - but it is not so important, with these hooks it is very simple to change generated output.
by , 17 years ago
Attachment: | 01-forms-options.2.diff added |
---|
comment:5 by , 14 years ago
Type: | → New feature |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|
comment:7 by , 14 years ago
Easy pickings: | unset |
---|---|
Resolution: | → invalid |
Status: | new → closed |
UI/UX: | unset |
A few of these items have been fixed already, the remainder should be opened as individual tickets, since they aren't interdependent.