Commits

Andriy Kornatskyy  committed 95ee8d3

Use last element available instead of first on widgets processing

  • Participants
  • Parent commits 71619b5

Comments (0)

Files changed (4)

File src/wheezy/html/builder.py

 
     def error(self):
         if self.errors:
-            return Tag('span', self.errors[0], {
+            return Tag('span', self.errors[-1], {
                 'class_': CSS_CLASS_ERROR
             })
         else:

File src/wheezy/html/factory.py

             name="name">John</textarea>
 
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input type="checkbox" id="accept" value="1"
-            name="accept" /><input type="hidden" name="accept" />
+        <input type="hidden" name="accept" /><input type="checkbox"
+            id="accept" value="1" name="accept" />
 
         >>> user.model.accept = True
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" type="checkbox" id="accept"
-            value="1" name="accept" /><input type="hidden"
-            name="accept" />
+        <input type="hidden" name="accept" /><input checked="checked"
+            type="checkbox" id="accept" value="1" name="accept" />
 
         >>> user.favorite_color.label('Color:')
         <label for="favorite-color">Color:</label>
         <textarea class="error" rows="9" cols="40" id="name"
             name="name">John</textarea>
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" name="accept" value="1"
-            class="error" type="checkbox" id="accept" /><input
-            type="hidden" name="accept" />
+        <input type="hidden" name="accept" /><input checked="checked"
+            name="accept" value="1" class="error" type="checkbox"
+            id="accept" />
         >>> user.favorite_color.label('Color:')
         <label class="error" for="favorite-color">Color:</label>
 
         if text is None:
             errors = self.errors.get('__ERROR__', None)
             if errors:
-                text = errors[0]
+                text = errors[-1]
         return self.info(text, class_=CSS_CLASS_ERROR_MESSAGE)
 
     def warning(self, text):

File src/wheezy/html/markup.py

         return ''.join(map(repr, self.tags))
 
     def __getattr__(self, name):
-        return getattr(self.tags[0], name)
+        return getattr(self.tags[-1], name)

File src/wheezy/html/widgets.py

 def checkbox(name, checked, attrs=None):
     """
         >>> checkbox('accept', True)  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" type="checkbox" id="accept"
-            value="1" name="accept" /><input type="hidden"
-            name="accept" />
+        <input type="hidden" name="accept" /><input checked="checked"
+            type="checkbox" id="accept" value="1" name="accept" />
         >>> checkbox('accept', False)  #doctest: +NORMALIZE_WHITESPACE
-        <input type="checkbox" id="accept" value="1" name="accept"
-            /><input type="hidden" name="accept" />
+        <input type="hidden" name="accept" /><input type="checkbox"
+            id="accept" value="1" name="accept" />
 
         >>> checkbox('accept', True,
         ...         attrs={'class_': 'b'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="b" checked="checked" name="accept"
-            type="checkbox" id="accept" value="1" /><input
-            type="hidden" name="accept" />
+        <input type="hidden" name="accept" /><input class="b"
+            checked="checked" name="accept" type="checkbox"
+            id="accept" value="1" />
      """
     tag_attrs = {
             'id': id(name),
     if attrs:
         tag_attrs.update(attrs)
     return Fragment(
-            Tag('input', attrs=tag_attrs),
-            Tag('input', attrs={'name': name, 'type': 'hidden'})
+            Tag('input', attrs={'name': name, 'type': 'hidden'}),
+            Tag('input', attrs=tag_attrs)
     )