Class for creating text input parameter widgets that allow users to enter free-form text.This class can be imported from the squirrels.parameters or the squirrels module.
Factory methods are class methods that create and configure parameter instances. These methods are typically used in the pyconfigs/parameters.py file to create the parameter configurations (which describes the “shape” of the parameter but does not include the realtime user selections).
Decorator for creating a simple text parameter that doesn’t involve user attributes or parent parameters.The body of the decorated function does not need to return anything (i.e., it can simply be pass).
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
Communicates to the API client for the type of input field to use. Must be one of “text”, “textarea”, “number”, “color”, “date”, “datetime-local”, “month”, “time”, and “password”.
Decorator for creating a parameter with options that can vary based on user attributes or parent parameter selections.The decorated function must return a list of TextParameterOption objects.
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
Communicates to the API client for the type of input field to use. Must be one of “text”, “textarea”, “number”, “color”, “date”, “datetime-local”, “month”, “time”, and “password”.
A user attribute (like “access_level”) that determines which options are visible to different users. The decorated function should return options with matching user_groups values.To use custom user fields defined in pyconfigs/user.py, prefix with custom_fields. (e.g., "custom_fields.department").
The name of a parent parameter that controls which options are visible. The decorated function should return options with parent_option_ids matching the parent’s selected value.
Decorator for creating a parameter populated from a database table or query using a TextDataSource.The decorated function must return a TextDataSource object.
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
A user attribute that determines which options from the data source are visible to different users.To use custom user fields defined in pyconfigs/user.py, prefix with custom_fields..
A TextValue object containing the user’s entered text. This object has transformation methods like apply(), apply_percent_wrap(), apply_as_bool(), apply_as_number(), and apply_as_datetime() for safe usage in queries via placeholders.
This example creates a multi-line text input using the textarea type.
Copy
from squirrels import parameters as p@p.TextParameter.create_simple( name="comments", label="Comments", default_text="", input_type="textarea", description="Enter your comments")def comments_default(): pass
Once parameters are configured, you can use instance methods in your models to access the entered text. The parameter instances are available through the context object (e.g., sqrl.prms).
The TextValue object returned by get_entered_text() cannot be directly converted to string. It must be used through placeholders for SQL injection safety.
Then, in the SQL model, use the placeholder as such:
Copy
-- models/federates/search_results.sqlSELECT *FROM productsWHERE product_name LIKE $search_text -- or :search_text for dbviews that use a sqlalchemy connection
This is the recommended way to use text parameters in SQL to prevent SQL injection.