# View Range-based Data ## Example Overview - **Objective**: This example demonstrates how to implement dynamic range-based data selection with a live preview visualization. Users can select a range (e.g., word count) and instantly see data distributions, such as the number of articles within the selected range. The integration with `django_tomselect` ensures a smooth user experience with enhanced dropdowns. - **Problem Solved**: It enables users to interactively select ranges and see associated data without requiring a page reload, improving data exploration and decision-making workflows. - **Features Highlighted**: - Dynamic range selection with `TomSelectChoiceField`. - Live data preview updates using HTMX. - **Use Case**: - Applications requiring interactive filtering and visualization, such as analytics dashboards or content management systems. - Scenarios where users need to select ranges dynamically, such as price filters, date ranges, or statistical data bins. **Visual Examples**   ## Key Code Segments ### Forms The form uses `TomSelectChoiceField` to allow users to select a range dynamically. :::{admonition} Form Definition :class: dropdown ```python class RangePreviewForm(forms.Form): """Form demonstrating dynamic range selection with live preview.""" word_count = TomSelectChoiceField( config=TomSelectConfig( url="autocomplete-page-count-range", value_field="value", label_field="label", css_framework="bootstrap5", placeholder="Select a word count range...", preload="focus", highlight=True, minimum_query_length=0, ), help_text="Select a word count range to see distribution visualization", ) ``` ::: **Explanation**: - The `word_count` field is configured with a `TomSelectConfig` object that connects to an autocomplete endpoint and allows range selection. - The `highlight` parameter ensures the selected range is visually prominent. ### Templates The form is rendered in the `range_preview.html` template, where HTMX is used to update the preview dynamically based on the selected range. :::{admonition} Template Code :class: dropdown ```html {% extends 'example/base_with_bootstrap5.html' %} {% block extra_header %} {{ form.media }} {% endblock %} {% block content %}