Styling Demos

Example Overview

This example renders responsive, dynamic <select> fields with django_tomselect across Default, Bootstrap 4, and Bootstrap 5 styling, covering both single and multiple selection. It is the place to see how a single css_framework setting adapts the same autocomplete, placeholder, tabular dropdown header, and create/manage features to your project’s chosen CSS framework.

Visual Examples

Screenshot: Single Selection Screenshot: Multiple Selection with Tabular Display


Key Code Segments

Forms

The DefaultStylingForm, Bootstrap4StylingForm, and Bootstrap5StylingForm in forms/basic_demos.py configures fields using TomSelectConfig for the preferred styling.

  • Purpose: This sets up a dropdown with an autocomplete endpoint (url), styling with preferred style, and a clear button plugin.


Template

The default.html, bs4.html, and bs5.html templates render the form using the specified styling. They extend the base layout and include the necessary CSS and JavaScript assets.


Autocomplete View

The autocomplete functionality is defined in the autocompletes.py file using AutocompleteModelView.

  • Here, we use skip_authorization to bypass the default authorization checks for demonstration purposes.

  • Any searches will use the name field of the Edition model.

  • The page_size parameter sets the number of results to return per page.

  • The value_fields parameter specifies the fields to return in the response.

  • The list_url, create_url, update_url, and delete_url parameters are the url names for the respective views, if available.

  • Purpose: Provides the backend logic for fetching autocomplete results, with filtering and ordering.


Views

We use standard Django views to render the form.


Design and Implementation Notes

Key Features

  • Dynamic styling: Uses the preferred styling.

  • Plugins: Includes plugins like clear_button and dropdown_footer to enhance UX.

Alternative Approaches

  • Use the “default” styling if Bootstrap is not integrated into the project.

  • Use additional plugins like dropdown_footer to add create and list buttons directly in the dropdown.