Code

Opened 6 years ago

Closed 3 years ago

#6631 closed New feature (invalid)

Additional options for newforms

Reported by: Petr Marhoun <petr.marhoun@…> Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: post10
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Attachments (4)

01-newforms-options.diff (9.3 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.
01-newforms-options.2.diff (9.1 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.
01-forms-options.diff (8.6 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.
01-forms-options.2.diff (8.6 KB) - added by Petr Marhoun <petr.marhoun@…> 6 years ago.

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

comment:1 Changed 6 years ago by PJCrosier

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

comment:2 Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

  • 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 Changed 6 years ago by telenieko

  • Keywords post10 added
  • Triage Stage changed from Unreviewed to Design decision needed

Please bring this to django-developers, if possible after 1.0

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

comment:4 Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

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.

Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

comment:5 Changed 3 years ago by julien

  • Type set to New feature

comment:6 Changed 3 years ago by julien

  • Severity set to Normal

comment:7 Changed 3 years ago by carljm

  • Easy pickings unset
  • Resolution set to invalid
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.