'This method returns a list of widgets which describes a form definition field. This
includes the field label, helptext, type, selectfield options, required/optional & layout'

def build_form_definition_field_widgets(self, trans, layout_grids, field_index, field, form_type):

    label = TextField(('field_label_' + str(field_index)), 40, field['label'])
    helptext = TextField(('field_helptext_' + str(field_index)), 40, field['helptext'])
    field_type_select_field = SelectField(('field_type_' + str(field_index)), refresh_on_change=True, refresh_on_change_values=[SelectField.__name__])
    field_type_options = []
    if (form_type == trans.model.FormDefinition.types.SAMPLE):
        for supported_field_type in trans.model.Sample.supported_field_types:
            if (supported_field_type.__name__ == field['type']):
                field_type_select_field.add_option(supported_field_type.__name__, supported_field_type.__name__, selected=True)
                if (supported_field_type.__name__ == SelectField.__name__):
                    field_type_options = self.__build_field_type_select_field_options(field, field_index)
            else:
                field_type_select_field.add_option(supported_field_type.__name__, supported_field_type.__name__)
    else:
        for supported_field_type in trans.model.FormDefinition.supported_field_types:
            if (supported_field_type.__name__ == field['type']):
                field_type_select_field.add_option(supported_field_type.__name__, supported_field_type.__name__, selected=True)
                if (supported_field_type.__name__ == SelectField.__name__):
                    field_type_options = self.__build_field_type_select_field_options(field, field_index)
            else:
                field_type_select_field.add_option(supported_field_type.__name__, supported_field_type.__name__)
    required = SelectField(('field_required_' + str(field_index)), display='radio')
    if (field['required'] == 'required'):
        required.add_option('Required', 'required', selected=True)
        required.add_option('Optional', 'optional')
    else:
        required.add_option('Required', 'required')
        required.add_option('Optional', 'optional', selected=True)
    if (layout_grids and (form_type == trans.model.FormDefinition.types.SAMPLE)):
        layout_select_field = SelectField(('field_layout_' + str(field_index)))
        for (index, grid_name) in enumerate(layout_grids):
            if (str(field.get('layout', None)) == str(index)):
                grid_selected = True
            else:
                grid_selected = False
            layout_select_field.add_option(('%i.    %s' % ((index + 1), grid_name)), index, selected=grid_selected)
    default_value = TextField(('field_default_' + str(field_index)), 40, field.get('default', ''))
    name = TextField(('field_name_' + str(field_index)), 40, field['name'])
    name_helptext = 'The    field    name    must    be    unique    for    each    field    and    must    contain    only    alphanumeric    characters    and    underscore    .'
    if (layout_grids and (form_type == trans.model.FormDefinition.types.SAMPLE)):
        return [('Field    label', label), ('Help    text', helptext), ('Type', field_type_select_field, 'Add    options    below', field_type_options), ('Default    value', default_value), ('', required), ('Select    the    grid    layout    to    place    this    field', layout_select_field), ('Field    name', name, name_helptext)]
    return [('Field    label', label), ('Help    text', helptext), ('Type', field_type_select_field, 'Add    options    below', field_type_options), ('Default    value', default_value), ('', required), ('Field    name', name, name_helptext)]
