diff --git a/doc/MANUAL.md b/doc/MANUAL.md index 789940c..df4a5b7 100644 --- a/doc/MANUAL.md +++ b/doc/MANUAL.md @@ -154,6 +154,9 @@ Structurally, they are made up of the following elements: view it, if you know its name. This is useful for other forms to redirect to this forms and such. + - **`style`**: A string of inline CSS which will be applied to the field. + **Optional**, **String**. + - **`fields`**: List of fields in the form. Each field is a dictionary. **Required**, **List of dictionaries**. diff --git a/examples/megacorp_acc/megacorp_acc.json b/examples/megacorp_acc/megacorp_acc.json index 6dbab1a..94836a9 100644 --- a/examples/megacorp_acc/megacorp_acc.json +++ b/examples/megacorp_acc/megacorp_acc.json @@ -25,7 +25,8 @@ { "name": "email_address", "title": "What's your email address?", - "type": "string" + "type": "string", + "style": "width: 300px;" } ] }, diff --git a/src/scriptform.py b/src/scriptform.py index fd38a1c..caff2a7 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -633,18 +633,18 @@ class WebAppHandler(BaseHTTPRequestHandler): class FormRender(): field_tpl = { - "string": u'', - "number": u'', - "integer": u'', - "float": u'', - "date": u'', - "file": u'', - "password": u'', - "text": u'', - "radio_option": u'{label}
', - "select_option": u'', - "select": u'', - "checkbox": u'', + "string": u'', + "number": u'', + "integer": u'', + "float": u'', + "date": u'', + "file": u'', + "password": u'', + "text": u'', + "radio_option": u'{label}
', + "select_option": u'', + "select": u'', + "checkbox": u'', } def __init__(self, form_def): @@ -676,63 +676,63 @@ class FormRender(): method = getattr(self, method_name, None) return method(**params) - def r_field_string(self, name, value, size=50, required=False, classes=[]): + def r_field_string(self, name, value, size=50, required=False, classes=[], style=""): tpl = self.field_tpl['string'] - return tpl.format(name=name, value=value, size=size, required=required, classes=classes) + return tpl.format(name=name, value=value, size=size, required=required, classes=classes, style=style) - def r_field_number(self, name, value, min=None, max=None, required=False, classes=[]): + def r_field_number(self, name, value, min=None, max=None, required=False, classes=[], style=""): tpl = self.field_tpl['number'] - return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes) + return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes, style=style) - def r_field_integer(self, name, value, min=None, max=None, required=False, classes=[]): + def r_field_integer(self, name, value, min=None, max=None, required=False, classes=[], style=""): tpl = self.field_tpl['integer'] - return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes) + return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes, style=style) - def r_field_float(self, name, value, min=None, max=None, required=False, classes=[]): + def r_field_float(self, name, value, min=None, max=None, required=False, classes=[], style=""): tpl = self.field_tpl['integer'] - return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes) + return tpl.format(name=name, value=value, min=min, max=max, required=required, classes=classes, style=style) - def r_field_date(self, name, value, required=False, classes=[]): + def r_field_date(self, name, value, required=False, classes=[], style=""): tpl = self.field_tpl['date'] - return tpl.format(name=name, value=value, required=required, classes=classes) + return tpl.format(name=name, value=value, required=required, classes=classes, style=style) - def r_field_file(self, name, required=False, classes=[]): + def r_field_file(self, name, required=False, classes=[], style=""): tpl = self.field_tpl['file'] - return tpl.format(name=name, required=required, classes=classes) + return tpl.format(name=name, required=required, classes=classes, style=style) - def r_field_password(self, name, value, min=None, required=False, classes=[]): + def r_field_password(self, name, value, min=None, required=False, classes=[], style=""): tpl = self.field_tpl['password'] - return tpl.format(name=name, value=value, min=min, required=required, classes=classes) + return tpl.format(name=name, value=value, min=min, required=required, classes=classes, style=style) - def r_field_text(self, name, value, rows=4, cols=80, required=False, classes=[]): + def r_field_text(self, name, value, rows=4, cols=80, required=False, classes=[], style=""): tpl = self.field_tpl['text'] - return tpl.format(name=name, value=value, rows=rows, cols=cols, required=required, classes=classes) + return tpl.format(name=name, value=value, rows=rows, cols=cols, required=required, classes=classes, style=style) - def r_field_radio(self, name, value, options, classes=[]): + def r_field_radio(self, name, value, options, classes=[], style=""): tpl_option = self.field_tpl['radio_option'] radio_elems = [] for o_value, o_label in options: checked = '' if o_value == value: checked = 'checked' - radio_elems.append(tpl_option.format(name=name, value=value, checked=checked, label=o_label, classes=classes)) + radio_elems.append(tpl_option.format(name=name, value=value, checked=checked, label=o_label, classes=classes, style=style)) return u''.join(radio_elems) - def r_field_checkbox(self, name, checked, classes=''): + def r_field_checkbox(self, name, checked, classes='', style=""): tpl = self.field_tpl['checkbox'] - return tpl.format(name=name, checked=checked, classes=classes) + return tpl.format(name=name, checked=checked, classes=classes, style=style) - def r_field_select(self, name, value, options, classes=[]): + def r_field_select(self, name, value, options, classes=[], style=""): tpl_option = self.field_tpl['select_option'] select_elems = [] for o_value, o_label in options: selected = '' if o_value == value: selected = 'selected' - select_elems.append(tpl_option.format(value=o_value, selected=selected, label=o_label)) + select_elems.append(tpl_option.format(value=o_value, selected=selected, label=o_label, style=style)) tpl = self.field_tpl['select'] - return tpl.format(name=name, select_elems=''.join(select_elems), classes=classes) + return tpl.format(name=name, select_elems=''.join(select_elems), classes=classes, style=style) def r_form_line(self, type, title, input, classes, errors): if type == 'checkbox': @@ -849,6 +849,8 @@ class ScriptFormWebApp(WebAppHandler): if field.get('hidden', None): params['classes'].append('hidden') + params["style"] = field.get("style", "") + if field['type'] not in ('file', 'checkbox'): params['value'] = form_values.get(field['name'], '') @@ -1023,7 +1025,6 @@ class ScriptFormWebApp(WebAppHandler): return path = os.path.join(form_config.static_dir, fname) - print path if not os.path.exists(path): self.send_error(404, "Not found") return