### Navigation

- index
- previous |
- Formbar 0.8.3 documentation »

# API

## Form

class `formbar.form.``Form`(config, item=None, dbsession=None, translate=None, change_page_callback={}, renderers={}, request=None, csrf_token=None, eval_url=None)

  Class for forms. The form will take care for rendering the form, validating the submitted data and saving the data back to the item.

  The form must be instanciated with an instance of an `Form` configuration and optional an SQLAlchemy mapped item.

  If an SQLAlchemy mapped item is provided there are some basic validation is done based on the defintion in the database. Further the save method will save the values directly into the database.

  If no item was provided than a dummy item will be created with the attributes of the configured fields in the form.

  `data` = None

    After submission this Dictionary will contain the validated data on successfull validation. Else this Dictionary will be empty

  `get_errors`(page=None)

    Returns a dictionary of all errors in the form. If page parameter is given, then only the errors for fields on the given page are returned. This dictionary will contain the errors if the validation fails. The key of the dictionary is the fieldname of the field. As a field can have more than one error the value is a list.

    Page: | Dictionary with errors
    Returns: | Dictionary with errors

  `get_warnings`(page=None)

    Returns a dictionary of all warnings in the form. If page parameter is given, then only the warnings for fields on the given page are returned. This dictionary will contain the warnings if the validation fails. The key of the dictionary is the fieldname of the field. As a field can have more than one warning the value is a list.

    Page: | Name of the page
    Returns: | Dictionary with warnings

  `has_errors`()

    Returns True if one of the fields in the form has errors

  `has_warnings`()

    Returns True if one of the fields in the form has warnings

  `loaded_data` = None

    This is the initial data loaded from the given item. Used to render the readonly forms

  `save`()

    Will save the validated data back into the item. In case of an SQLAlchemy mapped item the data will be stored into the database. :returns: Item with validated data.

  `submitted_data` = None

    The submitted data from the user. If validation fails, then this values are used to rerender the form.

  `validate`(submitted)

    Returns True if the validation succeeds else False. Validation of the data happens in three stages:

    1. Prevalidation. Custom rules that are checked before any datatype checks on type conversations are made. 2. Basic type checks and type conversation. Type checks and type conversation is done based on the data type of the field and further constraint defined in the database if the form is instanciated with an SQLAlchemy mapped item. 3. Postvalidation. Custom rules that are checked after the type conversation was done.

    All errors are stored in the errors dictionary through the process of validation. After the validation finished the values are stored in the data dictionary. In case there has been errors the dictionary will contain the origin submitted data.

    Submitted: | Dictionary with submitted values.
    Returns: | True or False

## Configuration

`formbar.config.``parse`(xml)

  Returns the parsed XML. This is a helper function to be used in connection with loading the configuration files. :xml: XML string to be parsed :returns: DOM of the parsed XML

`formbar.config.``load`(path)

  Return the parsed XML form the given file. The function will load the file located in path and than returns the parsed content.

class `formbar.config.``Config`(tree)

  Class for accessing the form configuration file. It provides methods to get certain elements from the configuration.

  `__init__`(tree)

    Initialize a configuration with the DOM tree of an XML configuration for the form. If tree is not an instance of an ElementTree than raise a TypeError

    Tree: | XML DOM tree of the configuration file

### Navigation

- index
- previous |
- Formbar 0.8.3 documentation »