Skip to content

Form Widgets

widgets

FileLinkWidget(base_path, base_url, attrs=None)

Bases: TextInput

TextInput with an adjacent "Open" link to the file if it exists on disk.

Renders a standard text input alongside a link button that opens the file in a new tab, constructed from base_url + the field value.

Parameters:

Name Type Description Default
base_path

Filesystem directory to check for file existence.

required
base_url

URL prefix used to build the download/view link.

required

ReadonlySelect

Bases: Select

Select widget that displays the selected choice as plain text.

Renders the display text of the selected value with a hidden input to preserve the value on form submission.

ReadonlyMultiSelect

Bases: SelectMultiple

SelectMultiple widget that displays selected choices as comma-separated text.

The actual <select> element is hidden; a visible text representation is shown alongside it so the values are still submitted with the form.

ReadOnlyInput

Bases: TextInput

TextInput that displays the value as plain text with a hidden input.

The visible text cannot be edited; the hidden <input> preserves the value for form submission. Used by ReadOnlyModelForm.

DateInput

Bases: DateInput

DateInput that renders as an HTML5 <input type="date"> element.

SingleCharSplitInput(split=2, *args, **kwargs)

Bases: TextInput

TextInput that splits entry into individual single-character boxes.

Renders split number of 1-character <input> elements. As each character is typed, focus advances to the next box. The concatenated value is stored in a hidden input for form submission.

Parameters:

Name Type Description Default
split

Number of single-character input boxes (default 2).

2

USAddressWidget(attrs=None)

Bases: Widget

Widget that renders five separate inputs for US address entry.

Displays fields for street address, street address line 2, city, a state dropdown (all 50 US states), and ZIP code. Data is submitted as a dict with keys street_address, street_address_2, city, state, zip_code.

Uses template django_reusable/widgets/us_address_widget.html.

format_value(value)

Format the value for display in the widget

value_from_datadict(data, files, name)

Extract address data from form submission

get_context(name, value, attrs)

Get context for template rendering

CurrencyInput(attrs=None)

Bases: TextInput

TextInput with client-side US currency formatting.

Adds a currency-input CSS class and includes django_reusable/js/currency-format.js which formats the value with $ sign and comma separators on blur. The raw numeric value is preserved for form submission.

format_value(value)

Format the value for display - keep as plain number for form processing