Skip to main content
Cascading parameters is a powerful feature in Squirrels that allows you to dynamically filter parameter options based on the selection of a parent parameter or the attributes of the authenticated user. This creates more intuitive and focused user experiences by showing only relevant options.
In this documentation, we refer to “select parameters” as single-select and multi-select parameters. Non-select parameters are DateParameter, NumberParameter, TextParameter, etc.

Overview

In Squirrels, a parameter’s available options can be filtered (or “cascaded”) based on two mechanisms:
  1. Parent parameter cascading: A child parameter’s options depend on what the user selects in a parent parameter
  2. User attribute cascading: A parameter’s options depend on attributes of the authenticated user
Both mechanisms work similarly: each parameter option specifies which parent values or user groups it belongs to, and at runtime, only matching options are shown to the user.

Parent-child cascading

Parent-child cascading allows you to link parameters so that the available options in a child parameter change based on what is selected in the parent parameter.

Basic example

Consider a scenario where you have a “Country” dropdown and a “City” dropdown. You only want to show cities that belong to the selected country:
pyconfigs/parameters.py
When the user selects “United States”, only New York, Los Angeles, and Chicago appear in the City dropdown. When “Canada” is selected, only Toronto and Vancouver appear.

How it works

The cascading mechanism works through two key components:
  1. parent_name: Specified in the factory method (create_with_options or create_from_source), this identifies which parameter is the parent
  2. parent_option_ids: Specified in each parameter option, this lists which parent option IDs make this option visible
At runtime, Squirrels:
  1. Gets the selected option(s) from the parent parameter
  2. Filters child options to those where parent_option_ids intersects with the parent’s selected IDs
  3. Returns only the matching options to the user

Multiple parent option IDs

A child option can be associated with multiple parent options. For example, a region that spans multiple countries:
For select parameters, each parent option ID can appear in zero or more child options. This means:
  • A parent option might have no corresponding child options
  • A parent option might have many corresponding child options
  • A child option can belong to multiple parent options

Using data sources

When parameter options come from a database table, use parent_id_col in the data source to specify cascading:
pyconfigs/parameters.py

Cascading for non-select parameters

While select parameters cascade their list of options, non-select parameters (DateParameter, NumberParameter, etc.) cascade their configuration. This allows you to change defaults, constraints, and ranges based on parent selections.

Example: Date parameter with cascading constraints

pyconfigs/parameters.py
When “FY 2023” is selected, the date picker is constrained to 2023 dates. When “FY 2024” is selected, the constraints switch to 2024.
For non-select child parameters, each parent option ID can appear in at most one child option. This is because non-select parameters use a single configuration rather than a list of selectable options.

Rules for parent parameters

Not all parameter types can be parents. The rules are:
Why the restriction? Non-select child parameters need exactly one configuration at any time. If the parent were a multi-select with multiple selections, it would be ambiguous which child configuration to use. Single-select parents always have exactly one selection.

User attribute cascading

User attribute cascading filters parameter options based on an attribute of the authenticated user. This is useful for role-based access control or personalization.

Basic example

pyconfigs/parameters.py
When a user with access_level="guest" makes a request, they only see the “Summary Report” option. A member user would see “Summary Report” and “Detailed Report”, while an admin user would see all three options.

How it works

The user attribute cascading mechanism works through two components:
  1. user_attribute: Specified in the factory method, this identifies which user attribute to check
  2. user_groups: Specified in each parameter option, this lists which attribute values make this option visible
At runtime, Squirrels:
  1. Gets the value of the specified attribute from the authenticated user
  2. Filters options to those where user_groups contains the user’s attribute value
  3. Returns only the matching options to the user

Using custom user fields

If you define custom fields in pyconfigs/user.py, you can use them for cascading by prefixing with custom_fields.:
pyconfigs/parameters.py

Same rules apply

The same rules that apply to parent-child parameter cascading also apply to user attribute cascading:
  • For select parameters: Each user group value can appear in zero or more options
  • For non-select parameters: Each user group value can appear in at most one option

Using data sources

When parameter options come from a database, use user_group_col:
pyconfigs/parameters.py

Combining parent and user attribute cascading

You can use both parent cascading and user attribute cascading on the same parameter:
pyconfigs/parameters.py
An option is only shown if both the parent parameter has one of the parent option IDs selected AND the user attribute value is in the user groups for that option.
When combining both cascading types for non-select parameters, each unique combination of (parent_option_id, user_group) can appear in at most one child option.

Disabled parameters

A parameter becomes disabled when it has no available options after filtering. This can happen when:
  • The parent parameter’s selection doesn’t match any parent_option_ids in the child’s options
  • The user’s attribute value doesn’t match any user_groups in the parameter’s options

Checking for disabled parameters

In context.py or data models, use sqrl.param_exists() to check if a parameter is enabled:
pyconfigs/context.py

Summary