• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.forms.widgets
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.forms.widgets¶

    Custom widgets for Django form fields.

    This module contains widgets that correspond to fields provided in djblets.forms.fields.

    class AmountSelectorWidget(unit_choices: List[Tuple[Optional[int], str]], number_attrs: Optional[Dict[str, Any]] = None, select_attrs: Optional[Dict[str, Any]] = None, attrs: Optional[Dict[str, Any]] = None)[source]¶

    Bases: MultiWidget

    A widget for editing an amount and its unit of measurement.

    New in version 3.3.

    template_name = 'djblets_forms/amount_selector_widget.html'[source]¶

    The name of the template used to render the widget.

    __init__(unit_choices: List[Tuple[Optional[int], str]], number_attrs: Optional[Dict[str, Any]] = None, select_attrs: Optional[Dict[str, Any]] = None, attrs: Optional[Dict[str, Any]] = None) → None[source]¶

    Initialize the widget.

    Parameters:
    • unit_choices (list of tuple) –

      The unit choices for the field.

      This should be a list of 2-tuples with the following entries:

      Tuple:
      • 0 (int or None) – The conversion factor of the unit to the base unit. The base unit must always have this value set to 1. For the rest of the units, this will be the number that you need to multiply a value in the base unit by in order to convert it to the given unit.

      • 1 (str) – The name for the unit.

      The list of unit choices should start with the base unit and have the rest of the units follow in increasing order of magnitude. You may set a conversion factor of None for a unit choice, which will allow you to save the value for this widget as None instead of as an integer amount. The None unit choice should be placed at the end of the list.

    • number_attrs (dict, optional) – Additional HTML element attributes for the NumberInput widget.

    • select_attrs (dict, optional) – Additional HTML element attributes for the Select widget.

    • attrs (dict, optional) – Additional HTML element attributes for the MultiWidget parent.

    decompress(value: Optional[int]) → Tuple[Optional[int], Optional[int]][source]¶

    Break up the value into an amount and unit tuple.

    This assumes that the value is stored in the base unit, and will find the most appropriate unit to display and convert the amount to that unit. The most appropriate unit is the largest unit where the amount can be converted to a whole number.

    Parameters:

    value (int or None) – The stored value.

    Returns:

    A 2-tuple of:

    Tuple:
    • 0 (int or None) – The amount in the unit.

    • 1 (int or None) – The integer representation of the unit.

    Return type:

    tuple

    value_from_datadict(data: Dict[str, Any], files: Dict[str, Any], name: str) → Optional[int][source]¶

    Return a value for the field from a submitted form.

    This serializes the data POSTed for the form into an integer that the field can use and validate. This will convert the integer value to the base unit.

    Args:
    data (dict):

    The dictionary containing form data.

    files (dict):

    The dictionary containing uploaded files.

    name (str):

    The field name for the value to load.

    Returns:

    The value to save in the field.

    Return type:

    int or None

    class ConditionsWidget(choices, mode_widget, choice_widget, operator_widget, choice_kwargs=None, attrs=None)[source]¶

    Bases: Widget

    A widget used to request a list of conditions from the user.

    This is used by ConditionsField() to allow the user to specify a list of possible conditions, composed of choices, operators, and values.

    The conditions are displayed as rows of fields. Each row contains a <select> for the condition choice, operator choice, and a choice-provided field for a value.

    Additional conditions can be added by the user dynamically.

    choices¶

    The condition choices for the field.

    Type:

    djblets.conditions.choices.ConditionChoices

    mode_widget¶

    The widget for selecting the mode.

    Type:

    django.forms.widgets.RadioSelect

    choice_widget¶

    The widget for selecting choices. One of these will be rendered for every row.

    Type:

    django.forms.widgets.Select

    operator_widget¶

    The widget for selecting operators. One of these will be rendered for every row.

    Type:

    django.forms.widgets.Select

    choice_kwargs¶

    Optional keyword arguments to pass to each BaseConditionChoice constructor. This is useful for more advanced conditions that need additional data from the form.

    This can be updated dynamically by the form during initialization.

    Type:

    dict

    template_name = 'djblets_forms/conditions_widget.html'[source]¶

    The name of the template used to render the widget.

    __init__(choices, mode_widget, choice_widget, operator_widget, choice_kwargs=None, attrs=None)[source]¶

    Initialize the widget.

    Parameters:
    • choices (djblets.conditions.choices.ConditionChoices) – The condition choices for the field.

    • mode_widget (django.forms.widgets.RadioSelect) – The widget for selecting the mode.

    • choice_widget (django.forms.widgets.Select) – The widget for selecting choices. One of these will be rendered for every row.

    • operator_widget (django.forms.widgets.Select) – The widget for selecting operators. One of these will be rendered for every row.

    • choice_kwargs (dict) – Optional keyword arguments to pass to each BaseConditionChoice constructor. This is useful for more advanced conditions that need additional data from the form.

    • attrs (dict, optional) – Additional HTML element attributes for the widget.

    value_from_datadict(data, files, name)[source]¶

    Return a value for the field from a submitted form.

    This serializes the data POSTed for the form into a format that the field can use and validate.

    Parameters:
    • data (django.http.request.QueryDict) – The dictionary containing form data.

    • files (django.http.request.QueryDict) – The dictionary containing uploaded files.

    • name (unicode) – The field name for the value to load.

    Returns:

    The value from the form data.

    Return type:

    object

    render(name, value, attrs=None, renderer=None)[source]¶

    Render the widget to HTML.

    This will serialize all the choices, operators, and existing conditions and render an HTML representation, along with setting up JavaScript support for configuring the conditions.

    Parameters:
    • name (unicode) – The base form field name of the widget.

    • value (dict) – The serialized condition set for the field.

    • attrs (dict, optional) – Additional HTML element attributes for the fields.

    • renderer (django.forms.renderers.BaseRenderer, optional) – The form renderer.

    Returns:

    The rendered HTML for the widget.

    Return type:

    django.utils.safestring.SafeText

    get_context(name, value, attrs)[source]¶

    Return context for the widget.

    This will serialize all the choices, operators, and existing conditions needed to render the widget.

    Parameters:
    • name (unicode) – The base form field name of the widget.

    • value (dict) – The serialized condition set for the field.

    • attrs (dict) – Additional HTML element attributes for the fields.

    Returns:

    The context data for the widget.

    Return type:

    dict

    __deepcopy__(memo)[source]¶

    Return a deep copy of the widget.

    This will return a deep copy of this widget and all subwidgets, so that a particular form instance can easily manipulate state without affecting other instances.

    Only the state that may be manipulated by an instance will be deep copied.

    Parameters:

    memo (dict) – The memo dictionary used to track IDs to objects.

    Returns:

    A deep copy of this widget’s instance.

    Return type:

    ConditionsWidget

    __annotations__ = {}¶
    class CopyableTextInput(attrs=None)[source]¶

    Bases: TextInput

    A TextInput widget that renders a link to copy its contents.

    template_name = 'djblets_forms/copyable_text_input.html'[source]¶
    render(name, value, attrs=None, renderer=None)[source]¶

    Render the widget.

    Parameters:
    • name (unicode) – The name of the widget.

    • value (unicode) – The value of the widget.

    • attrs (dict) – The attributes of the widget.

    • renderer (django.forms.renderers.BaseRenderer, optional) – The form renderer.

    Returns:

    The rendered widget.

    Return type:

    django.utils.safestring.SafeText

    __annotations__ = {}¶
    class ListEditWidget(attrs=None, sep=', ', value_widget=<class 'django.forms.widgets.TextInput'>)[source]¶

    Bases: Widget

    A widget for editing a list of values.

    template_name = 'djblets_forms/list_edit_widget.html'[source]¶
    __init__(attrs=None, sep=', ', value_widget=<class 'django.forms.widgets.TextInput'>)[source]¶

    Initialize the widget.

    Changed in version 3.0: Added the value_widget parameter and the ability for this widget to handle any list of values instead of only strings.

    Parameters:
    • attrs (dict, optional) – A dictionary containing HTML attributes to be set on the rendered widget.

    • sep (str, optional) – The item separator.

    • value_widget (django.forms.widgets.Widget, optional) – The widget for the values in the list.

    render(name, value, attrs=None, renderer=None)[source]¶

    Render the widget.

    Changed in version 3.0: The value parameter can be a string or a list of any type of values.

    Parameters:
    • name (str) – The field name.

    • value (list or str) – The field value.

    • attrs (dict, optional) – Additional attributes.

    • renderer (django.forms.renderers.BaseRenderer, optional) – The form renderer.

    Returns:

    The rendered widget.

    Return type:

    django.utils.safestring.SafeText

    get_context(name, value, attrs)[source]¶

    Return context for the widget.

    This will serialize all the values in the list of values using the value_widget.

    New in version 3.0.

    Parameters:
    • name (str) – The base form field name of the widget.

    • value (dict) – The list of values.

    • attrs (dict) – Additional HTML element attributes for the fields.

    Returns:

    The context data for the widget.

    Return type:

    dict

    value_from_datadict(data, files, name)[source]¶

    Return a value for the field from a submitted form.

    This serializes the data POSTed for the form into a format that the field can use and validate.

    New in version 3.0.

    Parameters:
    • data (django.http.request.QueryDict) – The dictionary containing form data.

    • files (django.http.request.QueryDict) – The dictionary containing uploaded files.

    • name (str) – The field name for the value to load.

    Returns:

    The list of values for the field or a string of separated values for legacy behavior.

    Return type:

    list or str

    id_for_label(id_)[source]¶

    Return the main ID to use for this widget.

    This intentionally returns None since there are multiple fields under this widget.

    Parameters:

    id (str) – The ID of the element.

    Returns:

    None so that no for= attribute is rendered on the label.

    Return type:

    str

    __annotations__ = {}¶
    class RelatedObjectWidget(multivalued=True)[source]¶

    Bases: HiddenInput

    A base class form widget that lets people select one or more objects.

    This is a base class. Extended classes must define their own render() method, to render their own widget with their own data.

    This should be used with relatedObjectSelectorView.es6.js, which extends a Backbone view to display data.

    is_hidden = False[source]¶
    __init__(multivalued=True)[source]¶

    Initialize the RelatedObjectWidget.

    Parameters:
    • local_site_name (unicode, optional) – The name of the LocalSite where the widget is being rendered.

    • multivalued (bool, optional) – Whether or not the widget should allow selecting multiple values.

    __annotations__ = {}¶

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • AmountSelectorWidget
      • AmountSelectorWidget.template_name
      • AmountSelectorWidget.__init__()
      • AmountSelectorWidget.decompress()
      • AmountSelectorWidget.value_from_datadict()
    • ConditionsWidget
      • ConditionsWidget.choices
      • ConditionsWidget.mode_widget
      • ConditionsWidget.choice_widget
      • ConditionsWidget.operator_widget
      • ConditionsWidget.choice_kwargs
      • ConditionsWidget.template_name
      • ConditionsWidget.__init__()
      • ConditionsWidget.value_from_datadict()
      • ConditionsWidget.render()
      • ConditionsWidget.get_context()
      • ConditionsWidget.__deepcopy__()
      • ConditionsWidget.__annotations__
    • CopyableTextInput
      • CopyableTextInput.template_name
      • CopyableTextInput.render()
      • CopyableTextInput.__annotations__
    • ListEditWidget
      • ListEditWidget.template_name
      • ListEditWidget.__init__()
      • ListEditWidget.render()
      • ListEditWidget.get_context()
      • ListEditWidget.value_from_datadict()
      • ListEditWidget.id_for_label()
      • ListEditWidget.__annotations__
    • RelatedObjectWidget
      • RelatedObjectWidget.is_hidden
      • RelatedObjectWidget.__init__()
      • RelatedObjectWidget.__annotations__