1. aryehg
  2. wtformako


Clone wiki

wtformako / Home


Here are some details about what I added/changed from the original WTForms

Added Labels to Elements in Lists and Container HTML Params

When rendering a list it now looks like the following and you can pass HTML attributes to the container LI element, simply prefix the HTML params with 'container_' :

  <li class="something" style="background-color: #f00;"><label for="someid">LABEL</label> <input id="someid" /></li>

This is accomplished with:

  ${ field( {'container_class': 'something', 'container_style': 'background-color: #f00;'} ) }

Added the ability to set data into field element for use later in template

This allows me to pass options to the fields from the controllers. Here is an example of passing JavaScript options for the jQuery Datepicker UI.

      birthdate  = DateField('Birthdate', default=date.today(), options={'js':
                                {'dateFormat': "'yy-mm-dd'",
                                  'changeMonth': 'false',
                                  'changeYear': 'true',
                                  'minDate': "'-100Y'",
                                  'maxDate': "'-18Y'",
                                  'yearRange': "'-100:-18'",
                           } )

My Template then has:

% if field.type == 'DateField':
        <script type="text/javascript" />
          jQuery(document).ready(function() {
              jQuery('#${field.id}').datepicker( {
                  ${ ", ".join(  [ "'%s': %s" % (ok, ov) for ok, ov in field.options.js.iteritems()]) | n}
                } );
% endif

Added ability to set attributes on the form object

In the controller:

  form = RegistrationForm(request.POST, action='/newaction', id='myformid', method='POST')

In the template:

   <form id="${form.id}" action="${form.action}" method="${form.method}" enctype="multipart/form-data" >

Added ability to set flags when creating a form element in a class

class MyForm(form):
  text = TextField('text', flags=['skip_label', 'othercustomflag']]

In the template I have something like:

<div id="${field.id}_container">
% if not field.flags.skip_label:
<label for="${field.id}">${field.label}</label>
% endif

I hope you find these updates helpful.