[Django] #17922: Add default "required" css classes to form labels

31 views
Skip to first unread message

Django

unread,
Mar 17, 2012, 4:27:36 AM3/17/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-------------------------------+--------------------
Reporter: hanson2010 | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------+--------------------
If a form field is required, add default "required" css class to its
label. The output will be as follows.

{{{
<tr>
<th><label for="id_name" class="required">Name:</label></th>
<td><input id="id_name" type="text" name="name" value="1" maxlength="256"
/></td>
</tr>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17922>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 8, 2012, 10:10:11 PM6/8/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------
Changes (by lukeplant):

* needs_better_patch: => 0
* needs_docs: => 1
* type: Uncategorized => New feature
* needs_tests: => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:1>

Django

unread,
Aug 25, 2012, 5:08:55 PM8/25/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------
Changes (by anonymous):

* version: 1.3 => master


Comment:

I'm added path, docs and corrected tests for a path at this pull request
https://github.com/django/django/pull/305

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:2>

Django

unread,
Aug 28, 2012, 4:53:20 PM8/28/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------
Changes (by apollo13):

* cc: apollo13 (added)


Comment:

What's the rationale for setting this on the label on not on the actual
input field (or even both)?

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:3>

Django

unread,
Aug 28, 2012, 9:50:23 PM8/28/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------

Comment (by hanson2010):

In most cases, the label of required fields should be in bolded style or
accompanied by an asterisk, while the actual input field left as usual.

Replying to [comment:3 apollo13]:

> What's the rationale for setting this on the label on not on the actual
input field (or even both)?

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:4>

Django

unread,
Aug 29, 2012, 4:13:16 AM8/29/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------
Changes (by d1ffuz0r):

* cc: d1fffuz0r@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:5>

Django

unread,
Oct 3, 2012, 5:08:20 AM10/3/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody
Type: New feature | Status: new

Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------
Changes (by claudep):

* needs_docs: 1 => 0
* needs_tests: 1 => 0


Comment:

Note that there is already a `required_css_class` settable attribute for
forms, documented here:
https://docs.djangoproject.com/en/dev/ref/forms/api/#styling-required-or-
erroneous-form-rows (see also #3512)

So when a form is output with `as_p`, `as_ul` or `as_tr`, the row itself
is already marked with the `required_css_class` value, hence the CSS to
style them is trivial. However, the problem remains when the field is
output with dict access (`{{ form.myfield.label_tag }}: {{ form.myfield
}}`). See for example the TODO comments in `auth/user/change_password.html
template`.

I will propose a new patch that only set the `required_css_class` in this
latter case.

The fact that `required_css_class` is not set by default on forms might be
the subject of another ticket...

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:6>

Django

unread,
Oct 3, 2012, 5:12:22 AM10/3/12
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+------------------------------------
Reporter: hanson2010 | Owner: nobody

Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+------------------------------------

Comment (by claudep):

Replying to [comment:6 claudep]:


> The fact that `required_css_class` is not set by default on forms might
be the subject of another ticket...

This is tracked in #14322

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:7>

Django

unread,
Feb 24, 2013, 5:38:41 AM2/24/13
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+-------------------------------------
Reporter: hanson2010 | Owner: bpeschier
Type: New feature | Status: assigned

Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+-------------------------------------
Changes (by bpeschier):

* keywords: => sprint2013
* owner: nobody => bpeschier
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:8>

Django

unread,
Jul 25, 2013, 12:44:24 PM7/25/13
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+-------------------------------------
Reporter: hanson2010 | Owner: bpeschier
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

Patch no longer applies cleanly.

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:9>

Django

unread,
Mar 3, 2014, 2:50:09 PM3/3/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042

Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------
Changes (by anubhav9042):

* owner: bpeschier => anubhav9042


Comment:

Please see this PR:
https://github.com/django/django/pull/2390

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:10>

Django

unread,
Mar 7, 2014, 10:28:28 AM3/7/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by apollo13):

I think we should use the "required" attribute from HTML5 and don't set
any css class.

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:11>

Django

unread,
Mar 7, 2014, 2:35:18 PM3/7/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by claudep):

Florian, would adding the `required` attribute on the widget help styling
the label (common use case) ? Of course, adding the HTML5 `required`
attribute is a very good idea, but I'm not sure it solves this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:12>

Django

unread,
Mar 8, 2014, 6:51:38 AM3/8/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by loic84):

An example of styling a label using the `:required` pseudoselector:

http://html5doctor.com/css3-pseudo-classes-and-html5-forms/#required-and-
optional-elements

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:13>

Django

unread,
Mar 8, 2014, 8:31:31 AM3/8/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by claudep):

Thanks Loïc. Unfortunately, these seems to work only when the label
follows the input, not the reverse :-(

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:14>

Django

unread,
Mar 8, 2014, 11:11:29 AM3/8/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by loic84):

True, CSS can't match backwards, it'd be workable from the
`<label><input></label>` syntax, but that's not very practical.

One day we'll hopefully be able to pick the actual subject of a CSS
selector... (cf. http://dev.w3.org/csswg/selectors4/#subject)

Personally I'm a bit reluctant adding styling information from the Python
side, this things IMO belong to the template layer, but in this specific
case, `required_css_class` is optional so I guess it's not that bad.

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:15>

Django

unread,
Mar 23, 2014, 12:18:13 PM3/23/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------
Changes (by anubhav9042):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:16>

Django

unread,
Mar 24, 2014, 8:12:59 AM3/24/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed

Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"416a8580232075d569cf3c386a97067884c67a60"]:
{{{
#!CommitTicketReference repository=""
revision="416a8580232075d569cf3c386a97067884c67a60"
Fixed #17922 -- Added required_css_class to form label.

Thanks hanson2010 for the suggestion.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:17>

Django

unread,
Mar 24, 2014, 8:53:36 AM3/24/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by timo):

I created #22329 as a follow-up to this ticket to address the TODOs in the
admin templates that Claude mentioned in comment 6.

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:18>

Django

unread,
Mar 29, 2014, 9:06:30 AM3/29/14
to django-...@googlegroups.com
#17922: Add default "required" css classes to form labels
-----------------------------+---------------------------------------
Reporter: hanson2010 | Owner: anubhav9042
Type: New feature | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: sprint2013 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-----------------------------+---------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"ed4c2e1c0d9e43c09767b02fd8b4bd74a5dfe512"]:
{{{
#!CommitTicketReference repository=""
revision="ed4c2e1c0d9e43c09767b02fd8b4bd74a5dfe512"
Fixed #22329 -- Used label_tag() in some admin auth templates.

refs #17922.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17922#comment:19>

Reply all
Reply to author
Forward
0 new messages