Logo Search packages:      
Sourcecode: zope-cmfplone version File versions

def zope-cmfplone-2.0.4::FormTool::CMFForm::addField (   self,
  field_id,
  fieldType,
  group = None,
  kwargs 
)

Adds a Formulator Field to the wrapped BasicForm.

fieldType: An abbreviation for the Field type.
    'String' generates a StringField, 'Int' generates an IntField, etc.
    Uses a StringField if no suitable Field type is found.
field_id: Name of the variable in question.  Note that Formulator adds
    'field_' to variable names, so you will need to refer to the variable
    foo as field_foo in form page templates.
group: Formulator group for the field.

Additional arguments: addField passes all other arguments on to the
    new Field object.  In addition, it allows you to modify the
    Field's error messages by passing in arguments of the form
    name_of_message = 'New error message'

See Formulator.StandardFields for details.

Definition at line 425 of file FormTool.py.

00425                                                                  :
        """
        Adds a Formulator Field to the wrapped BasicForm.

        fieldType: An abbreviation for the Field type.
            'String' generates a StringField, 'Int' generates an IntField, etc.
            Uses a StringField if no suitable Field type is found.
        field_id: Name of the variable in question.  Note that Formulator adds
            'field_' to variable names, so you will need to refer to the variable
            foo as field_foo in form page templates.
        group: Formulator group for the field.

        Additional arguments: addField passes all other arguments on to the
            new Field object.  In addition, it allows you to modify the
            Field's error messages by passing in arguments of the form
            name_of_message = 'New error message'

        See Formulator.StandardFields for details.
        """

        if fieldType[-5:]!='Field':
            fieldType = fieldType+'Field'

        formulatorFieldClass = None

        if hasattr(StandardFields, fieldType):
            formulatorFieldClass = getattr(StandardFields, fieldType)
        else:
            formulatorFieldClass = getattr(StandardFields, 'StringField')

        # pass a title parameter to the Field
        kwargs['title'] = field_id

        fieldObject = apply(formulatorFieldClass, (field_id, ), kwargs)

        # alter Field error messages
        # Note: This messes with Formulator innards and may break in the future.
        # Unfortunately, Formulator doesn't do this already in Field.__init__
        # and there isn't a Python-oriented method for altering message values
        # so at present it's the only option.
        for arg in kwargs.keys():
            if fieldObject.message_values.has_key(arg):
                fieldObject.message_values[arg] = kwargs[arg]

        # Add the new Field to the wrapped BasicForm object
        BasicForm.add_field(self, fieldObject, group)


    security.declarePublic('validate')
    def validate(self, REQUEST, errors=None):


Generated by  Doxygen 1.6.0   Back to index