Wrapper for raw text entered into TextParameter widgets
Wrapper class for raw text entered into TextParameter widgets. It is returned by methods such as TextParameter.get_entered_text() so that the text cannot be accidentally treated as a plain string (for example, when building SQL).Instead of converting a TextValue directly to a string, you transform it using helper methods or pass it to APIs such as ContextArgs.set_placeholder, which safely unwrap the underlying text.Instances of TextValue are created by Squirrels and returned from parameter methods; you should not instantiate this class directly in your project code.If TextValue is needed for type annotation, it can be imported from the squirrels.types or squirrels module.
The TextValue class is primarily used as a type hint in pyconfigs/context.py. You receive TextValue instances from methods like TextParameter.get_entered_text(), then transform them using the provided methods before passing to APIs that safely handle the text.
from typing import Anyfrom squirrels import arguments as args, parameters as p, TextValuedef main(ctx: dict[str, Any], sqrl: args.ContextArgs) -> None: if sqrl.param_exists("my_text_param"): my_text_param = sqrl.prms["my_text_param"] assert isinstance(my_text_param, p.TextParameter) # Get text parameter value as TextValue text_value: TextValue = my_text_param.get_entered_text() # Wrap with % for SQL LIKE pattern matching search_pattern = text_value.apply_percent_wrap() sqrl.set_placeholder("search_pattern", search_pattern)