Reed O'Brien avatar Reed O'Brien committed 061501b

add type_ arg to button to allow for reset input

Comments (0)

Files changed (3)

         whatever is passed as ``name``.  E.g. if ``name`` is passed as
         ``submit``, ``title`` will be ``Submit``.
 
+    type_
+        The value used as the type of button. The HTML spec supports 
+        ``submit``, ``reset`` and ``button``. Default: ``submit``. 
+
     value
         The value used as the value of the button when rendered (the
         ``value`` attribute of the button or input tag resulting from
         a form rendering).  Default: same as ``name`` passed.
     """
-    def __init__(self, name='submit', title=None, value=None):
+    def __init__(self, name='submit', title=None, type_='submit', value=None):
         if title is None:
             title = name.capitalize()
         if value is None:
             value = name
         self.name = name
         self.title = title
+        self.type_ = type_
         self.value = value

deform/templates/form.pt

           <button 
               id="${field.formid+button.name}"
               name="${button.name}"
-              type="submit"
+              type="${button.type_}"
               class="btnText submit"
               value="${button.value}">
             <span>${button.title}</span>

deform/tests/test_form.py

         button = self._makeOne()
         self.assertEqual(button.title, 'Submit')
 
+    def test_ctor_type_None(self):
+        button = self._makeOne()
+        self.assertEqual(button.type_, 'submit')
+
     def test_ctor_value_None(self):
         button = self._makeOne()
         self.assertEqual(button.value, 'submit')
 
     def test_ctor(self):
-        button = self._makeOne(name='name', title='title', value='value')
+        button = self._makeOne(name='name', title='title', 
+                               type_='type', value='value')
         self.assertEqual(button.value, 'value')
         self.assertEqual(button.name, 'name')
         self.assertEqual(button.title, 'title')
+        self.assertEqual(button.type_, 'type')
 
 class TestRaw(unittest.TestCase):
     def _makeOne(self, val):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.