Ignore:
Timestamp:
Jan 12, 2009, 9:10:58 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@158
Message:

Selectively render Data Forms fields depending on form type.

Author: ralphm.
Reviewer: tofu.
Fixes #40.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/data_form.py

    r48 r50  
    11# -*- test-case-name: wokkel.test.test_data_form -*-
    22#
    3 # Copyright (c) 2003-2008 Ralph Meijer
     3# Copyright (c) 2003-2009 Ralph Meijer
    44# See LICENSE for details.
    55
     
    229229            self.values = newValues
    230230
    231     def toElement(self):
     231    def toElement(self, asForm=False):
    232232        """
    233233        Return the DOM representation of this Field.
     
    239239
    240240        field = domish.Element((NS_X_DATA, 'field'))
    241         field['type'] = self.fieldType
     241
     242        if asForm or self.fieldType != 'text-single':
     243            field['type'] = self.fieldType
    242244
    243245        if self.var is not None:
     
    249251            field.addElement('value', content=value)
    250252
    251         if self.fieldType in ('list-single', 'list-multi'):
    252             for option in self.options:
    253                 field.addChild(option.toElement())
    254 
    255         if self.label is not None:
    256             field['label'] = self.label
    257 
    258         if self.desc is not None:
    259             field.addElement('desc', content=self.desc)
    260 
    261         if self.required:
    262             field.addElement('required')
     253        if asForm:
     254            if self.fieldType in ('list-single', 'list-multi'):
     255                for option in self.options:
     256                    field.addChild(option.toElement())
     257
     258            if self.label is not None:
     259                field['label'] = self.label
     260
     261            if self.desc is not None:
     262                field.addElement('desc', content=self.desc)
     263
     264            if self.required:
     265                field.addElement('required')
    263266
    264267        return field
     
    425428
    426429        for field in self.fieldList:
    427             form.addChild(field.toElement())
     430            form.addChild(field.toElement(self.formType=='form'))
    428431
    429432        return form
Note: See TracChangeset for help on using the changeset viewer.