tailbone.forms

Forms Library

class tailbone.forms.Form(fields=None, schema=None, request=None, readonly=False, readonly_fields=[], model_instance=None, model_class=None, appstruct=<object object>, nodes={}, enums={}, labels={}, assume_local_times=False, renderers=None, renderer_kwargs={}, hidden={}, widgets={}, defaults={}, validators={}, required={}, helptext={}, focus_spec=None, action_url=None, cancel_url=None, vue_tagname=None, vuejs_component_kwargs=None, vuejs_field_converters={}, json_data={}, included_templates={}, can_edit_help=False, edit_help_url=None, route_prefix=None, **kwargs)[source]

Base class for all forms.

property component

DEPRECATED - use vue_tagname instead.

property component_studly

DEPRECATED - use vue_component instead.

get_vuejs_model_value(field)[source]

This method must return “raw” JS which will be assigned as the initial model value for the given field. This JS will be written as part of the overall response, to be interpreted on the client side.

has_helptext(key)[source]

Returns boolean indicating whether the given field has accompanying help text.

include_template(template, context)[source]

Declare a JS template as required by the current form. This template will then be included in the final page, so all widgets behave correctly.

jsonify_value(value)[source]

Take a Python value and convert to JSON

make_fields()[source]

Return a default list of fields, based on model_class.

make_renderers()[source]

Return a default set of field renderers, based on model_class.

render_field_complete(fieldname, bfield_attrs={}, session=None)[source]

Render the given field completely, i.e. with <b-field> wrapper. Note that this is meant to render editable fields, i.e. showing a widget, unless the field input is hidden. In other words it’s not for “readonly” fields.

render_field_readonly(field_name, **kwargs)[source]

Render the given field completely, but in read-only fashion.

Note that this method will generate the wrapper div and label, as well as the field value.

render_helptext(key)[source]

Render the help text for the given field.

render_vuejs_component(**kwargs)[source]

Render the Vue.js component HTML for the form.

Most typically this is something like:

<tailbone-form :configure-fields-help="configureFieldsHelp">
</tailbone-form>
set_default(key, value)[source]

Set the default value for a given field.

set_helptext(key, value, dynamic=False)[source]

Set the help text for a given field.

set_input_handler(key, value)[source]

Convenience method to assign “input handler” callback code for the given field.

set_json_data(key, value)[source]

Establish a data value for use in client-side JS. This value will be JSON-encoded and made available to the <tailbone-form> component within the client page.

set_required(key, required=True)[source]

Set whether or not value is required for a given field.

set_validator(key, validator)[source]

Set the validator for the schema node represented by the given key.

Parameters:
  • key – Normally this the name of one of the fields contained in the form. It can also be None in which case the validator pertains to the form at large instead of one of the fields.

  • validator – Callable which accepts (node, value) args.

validate(*args, **kwargs)[source]

Try to validate the form.

This should work whether data was submitted as classic POST data, or as JSON body.

Returns:

True if form data is valid, otherwise False.

property vue_component

String name for the Vue component, e.g. 'TailboneGrid'.

This is a generated value based on vue_tagname.