From 56b117cd94b5939c55ba7b369953b66d95e15777 Mon Sep 17 00:00:00 2001
From: Aurélien Bompard <aurelien@bompard.org>
Date: Oct 19 2017 09:42:04 +0000
Subject: Improve upon commit f6a511bf


---

diff --git a/hubs/static/client/app/components/SimpleWidgetConfig.js b/hubs/static/client/app/components/SimpleWidgetConfig.js
index 8228438..24d8e24 100644
--- a/hubs/static/client/app/components/SimpleWidgetConfig.js
+++ b/hubs/static/client/app/components/SimpleWidgetConfig.js
@@ -11,14 +11,15 @@ export default class SimpleWidgetConfig extends React.Component {
 
   render() {
     let fields = this.props.widget.params.map((field) => {
+      const attributes = {
+        className: "form-control",
+        ...field.renderAttributes
+      };
       return (
         <fieldset className="form-group row" key={field.name}>
           <strong>{field.label}</strong>
           <field.renderTag
-            className="form-control"
-            type={
-              field.renderTag === "input" ? field.renderType : null
-            }
+            {...attributes}
             value={this.props.values[field.name] || ""}
             name={field.name}
             onChange={(e) => {
diff --git a/hubs/tests/test_widget_base.py b/hubs/tests/test_widget_base.py
index d416897..03bb58e 100644
--- a/hubs/tests/test_widget_base.py
+++ b/hubs/tests/test_widget_base.py
@@ -161,7 +161,7 @@ class WidgetTest(APPTest):
                  'label': 'Text',
                  'name': 'text',
                  'renderTag': 'input',
-                 'renderType': 'text',
+                 'renderAttributes': {'type': 'text'},
                  },
             ],
             'position': 'right',
diff --git a/hubs/tests/widgets/test_halp.py b/hubs/tests/widgets/test_halp.py
index 673ae66..b12401e 100644
--- a/hubs/tests/widgets/test_halp.py
+++ b/hubs/tests/widgets/test_halp.py
@@ -129,14 +129,14 @@ class HalpViewsTestCase(WidgetTest):
                  'label': 'Hubs',
                  'name': 'hubs',
                  'renderTag': 'input',
-                 'renderType': 'text',
+                 'renderAttributes': {'type': 'text'},
                  },
                 {'default': 4,
                  'help': 'The number of requests per page to display.',
                  'label': 'Requests per page',
                  'name': 'per_page',
                  'renderTag': 'input',
-                 'renderType': 'text',
+                 'renderAttributes': {'type': 'text'},
                  },
             ],
             'position': 'right',
diff --git a/hubs/widgets/parameters.py b/hubs/widgets/parameters.py
index 43c672e..0b04bff 100644
--- a/hubs/widgets/parameters.py
+++ b/hubs/widgets/parameters.py
@@ -29,8 +29,8 @@ class WidgetParameter(object):
             viewing the widget, it will only be available in the widget
             configuration.
         render_tag (str): The HTML tag to use when rendering.
-        render_type (str): The HTML type attribute to use when rendering if the
-            tag is ``input``.
+        render_attributes (dict): A mapping of HTML attribute names to values
+            to use when rendering.
     """
 
     _defaults = {
@@ -40,13 +40,15 @@ class WidgetParameter(object):
         "validator": Noop,
         "secret": False,
         "render_tag": "input",
-        "render_type": "text",
+        "render_attributes": {},
     }
 
     def __init__(self, name, **kwargs):
         self.name = name
         for attr, default in self._defaults.items():
             setattr(self, attr, kwargs.pop(attr, default))
+        if self.render_tag == "input" and "type" not in self.render_attributes:
+            self.render_attributes["type"] = "text"
         for kw in kwargs:
             raise TypeError("Invalid argument: %s" % kw)
 
@@ -60,6 +62,6 @@ class WidgetParameter(object):
             label=self.label,
             default=self.default,
             renderTag=self.render_tag,
-            renderType=self.render_type,
+            renderAttributes=self.render_attributes,
             help=self.help,
             )

