Skip to content

Loading…

Avoid duplicate label for 'checked password widget' and add 'required' span on confirmation field. #38

Closed
wants to merge 4 commits into from

3 participants

@malthe
Pylons Project member

Don't include 'duplicate' label for initial password field; most likely, the field itself will have a title 'Enter password' and there's no reason to repeat that. Besides, it makes it very difficult to style the form. Also, add the 'required' span element on the confirmation field if applicable.

malthe added some commits
@malthe malthe Don't include 'duplicate' label for initial password field; most like…
…ly, the field itself will have a title 'Enter password' and there's no reason to repeat that. Besides, it makes it very difficult to style the form. Also, add the 'required' span element on the confirmation field if applicable.
363fd3d
@malthe malthe Add an additional css class to each mapping item corresponding to the…
… widget class name, but mangled such that the camel case class name appears in lowercase with dashes separating words.
a83dd03
@malthe malthe Merge branch 'master' of https://github.com/Pylons/deform 8df076e
@malthe malthe Fixed template logic: only if the error is defined may we concatenate…
… with a single space.
7465723
@kiorky
Pylons Project member

Please add the class just in addtionnal mode like:

class="field ${field.error and ' ' + field.widget.error_class} ${field.widget.css_name}${field.error and ' ' + field.widget.error_class}"
@kiorky
Pylons Project member

Please commit in a separate branch the css stuff.
Other is irrelevant i think for deform.

@sontek
Pylons Project member

The pull request was created 9 months ago and he hasn't responded to the requests. Is this still relevant?

@kiorky
Pylons Project member

That was my question at first and wanted malthe to answer...
We may close it next month (for the record)...

@malthe
Pylons Project member

You can just cherry-pick whatever commits you like from this.

I don't think I need to set up multiple branches in order to contribute these patches.

@kiorky kiorky closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2011
  1. @malthe

    Don't include 'duplicate' label for initial password field; most like…

    malthe committed
    …ly, the field itself will have a title 'Enter password' and there's no reason to repeat that. Besides, it makes it very difficult to style the form. Also, add the 'required' span element on the confirmation field if applicable.
  2. @malthe

    Add an additional css class to each mapping item corresponding to the…

    malthe committed
    … widget class name, but mangled such that the camel case class name appears in lowercase with dashes separating words.
  3. @malthe
Commits on Aug 14, 2011
  1. @malthe
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 3 deletions.
  1. +7 −0 CHANGES.txt
  2. +3 −2 deform/templates/checked_password.pt
  3. +2 −1 deform/templates/mapping_item.pt
  4. +8 −0 deform/tests/test_widget.py
  5. +14 −0 deform/widget.py
View
7 CHANGES.txt
@@ -1,6 +1,13 @@
Changes
=======
+In next release ...
+
+- The mapping item widget now adds a css class corresponding to the
+ widget class name, but with camel-case converted into dash-separated
+ lowercase segments, e.g. ``TextInputWidget`` becomes
+ ``"text-input-widget"``.
+
0.9.3 (2011-08-10)
------------------
View
5 deform/templates/checked_password.pt
@@ -2,12 +2,13 @@
<input type="hidden" name="__start__" value="${field.name}:mapping"/>
<ul>
<li>
- <label for="${field.oid}" i18n:translate="">Password</label>
<input type="password" name="value" value="${cstruct}"
tal:attributes="size field.widget.size" id="${field.oid}"/>
</li>
<li>
- <label for="${field.oid}-confirm" i18n:translate="">Confirm Password</label>
+ <label class="desc" for="${field.oid}-confirm" i18n:translate=""
+ >Confirm password<span tal:condition="field.required" class="req"
+ id="req-${field.oid}">*</span></label>
<input type="password" name="confirm" value="${confirm}"
tal:attributes="size field.widget.size;
class field.widget.css_class"
View
3 deform/templates/mapping_item.pt
@@ -1,7 +1,8 @@
-<li class="field${field.error and ' ' + field.widget.error_class}"
+<li class="field ${field.widget.css_name}${error and ' ' + error}"
title="${field.description}"
id="item-${field.oid}"
tal:omit-tag="field.widget.hidden"
+ tal:define="error field.error and field.widget.error_class"
i18n:domain="deform">
<!-- mapping_item -->
<label tal:condition="not (field.widget.hidden or
View
8 deform/tests/test_widget.py
@@ -19,6 +19,14 @@ def test_ctor(self):
self.assertEqual(widget.a, 1)
self.assertEqual(widget.b, 2)
+ def test_css_name(self):
+ from deform.widget import Widget
+
+ class StubWidget(Widget):
+ pass
+
+ self.assertEqual(StubWidget().css_name, 'stub-widget')
+
def test_serialize(self):
widget = self._makeOne()
self.assertRaises(NotImplementedError, widget.serialize, None, None)
View
14 deform/widget.py
@@ -1,3 +1,4 @@
+import re
import csv
import random
import string
@@ -15,6 +16,15 @@
import simplejson as json
+re_c1 = re.compile('(.)([A-Z][a-z]+)')
+re_c2 = re.compile('([a-z0-9])([A-Z])')
+
+
+def camel_to_css_class_name(name):
+ s1 = re_c1.sub(r'\1-\2', name)
+ return re_c2.sub(r'\1-\2', s1).lower()
+
+
class Widget(object):
"""
A widget is the building block for rendering logic. The
@@ -107,6 +117,10 @@ class Widget(object):
def __init__(self, **kw):
self.__dict__.update(kw)
+ @property
+ def css_name(self):
+ return camel_to_css_class_name(type(self).__name__)
+
def serialize(self, field, cstruct, readonly=False):
"""
The ``serialize`` method of a widget must serialize a
Something went wrong with that request. Please try again.