web/formwidgets.py
changeset 3890 d7a270f50f54
parent 3720 5376aaadd16b
parent 3803 414bb8439002
child 3998 94cc7cad3d2d
--- a/web/formwidgets.py	Sun Nov 08 21:53:18 2009 +0100
+++ b/web/formwidgets.py	Fri Nov 20 19:35:54 2009 +0100
@@ -13,6 +13,7 @@
 from cubicweb.common import tags, uilib
 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE, ProcessFormError
 
+from logilab.mtconverter import xml_escape
 
 class FieldWidget(object):
     """abstract widget class"""
@@ -472,7 +473,12 @@
                  setdomid=None, settabindex=None,
                  name='', value='', onclick=None, cwaction=None):
         super(Button, self).__init__(attrs, setdomid, settabindex)
-        self.label = label
+        if isinstance(label, tuple):
+            self.label = label[0]
+            self.icon = label[1]
+        else:
+            self.label = label
+            self.icon = None
         self.name = name
         self.value = ''
         self.onclick = onclick
@@ -494,7 +500,12 @@
                 attrs['id'] = self.name
         if self.settabindex and not 'tabindex' in attrs:
             attrs['tabindex'] = form._cw.next_tabindex()
-        return tags.input(value=label, type=self.type, **attrs)
+        if self.icon:
+            img = tags.img(src=form._cw.external_resource(self.icon), alt=self.icon)
+        else:
+            img = u''
+        return tags.button(img + xml_escape(label), escapecontent=False,
+                           value=label, type=self.type, **attrs)
 
 
 class SubmitButton(Button):