uf.rjsf_config
RJSF customization layer for uf.
Provides configuration classes and builders for customizing RJSF form generation beyond the defaults, including field widgets, UI options, and validation rules.
- class uf.rjsf_config.ConditionalFieldConfig(field_name: str, *, condition: dict, then_schema: dict | None = None, else_schema: dict | None = None)[source]
Configuration for conditional field display.
Allows fields to be shown/hidden based on the values of other fields.
Example
>>> # Show 'other_reason' field only when reason is 'other' >>> config = ConditionalFieldConfig( ... 'other_reason', ... condition={'reason': {'const': 'other'}} ... )
- class uf.rjsf_config.RjsfConfigBuilder[source]
Builder for RJSF configurations with sensible defaults.
This class helps construct RJSF specifications by providing a fluent interface for configuring fields.
Example
>>> builder = RjsfConfigBuilder() >>> builder.field('email', RjsfFieldConfig(format='email')) >>> builder.field('message', RjsfFieldConfig(widget='textarea')) >>> spec = builder.build(base_schema)
- build(base_schema: dict, base_ui_schema: dict | None = None) dict[source]
Build the final RJSF specification.
- Parameters:
base_schema – Base JSON Schema to augment
base_ui_schema – Optional base UI Schema to augment
- Returns:
Dictionary with ‘schema’ and ‘uiSchema’ keys
- class_names(class_names: str) RjsfConfigBuilder[source]
Set CSS class names for the form.
- Parameters:
class_names – Space-separated CSS class names
- Returns:
Self for method chaining
- field(param_name: str, config: RjsfFieldConfig) RjsfConfigBuilder[source]
Configure a specific field.
- Parameters:
param_name – Name of the parameter/field
config – Configuration for the field
- Returns:
Self for method chaining
- order(field_order: list[str]) RjsfConfigBuilder[source]
Set the order of fields in the form.
- Parameters:
field_order – List of field names in desired order
- Returns:
Self for method chaining
- class uf.rjsf_config.RjsfFieldConfig(widget: str | None = None, ui_options: dict = <factory>, format: str | None = None, enum: list | None = None, description: str | None = None, placeholder: str | None = None, title: str | None = None, disabled: bool = False, readonly: bool = False, hidden: bool = False, default: Any | None = None)[source]
Configuration for individual form fields.
This class allows fine-grained control over how form fields are rendered in the RJSF interface.
- widget
Widget type (e.g., ‘textarea’, ‘select’, ‘radio’, ‘date’)
- Type:
str | None
- ui_options
Additional UI options for the widget
- Type:
dict
- format
JSON Schema format (e.g., ‘email’, ‘uri’, ‘date-time’)
- Type:
str | None
- enum
List of allowed values (for dropdowns)
- Type:
list | None
- description
Field description/help text
- Type:
str | None
- placeholder
Placeholder text for the input
- Type:
str | None
- title
Custom title for the field
- Type:
str | None
- disabled
Whether the field is disabled
- Type:
bool
- readonly
Whether the field is read-only
- Type:
bool
Whether to hide the field
- Type:
bool
- default
Default value for the field
- Type:
Any | None
Example
>>> email_config = RjsfFieldConfig( ... widget='email', ... format='email', ... placeholder='user@example.com' ... )
- uf.rjsf_config.apply_field_configs(schema: dict, ui_schema: dict, field_configs: dict[str, RjsfFieldConfig]) tuple[dict, dict][source]
Apply field configurations to existing schemas.
- Parameters:
schema – JSON Schema to modify
ui_schema – UI Schema to modify
field_configs – Mapping of field names to configurations
- Returns:
Tuple of (modified_schema, modified_ui_schema)
Example
>>> configs = { ... 'email': get_field_config('email'), ... 'bio': get_field_config('multiline_text'), ... } >>> schema, ui_schema = apply_field_configs(schema, ui_schema, configs)
- uf.rjsf_config.get_field_config(config_name: str) RjsfFieldConfig[source]
Get a predefined field configuration by name.
- Parameters:
config_name – Name of the configuration (e.g., ‘email’, ‘multiline_text’)
- Returns:
RjsfFieldConfig instance
- Raises:
KeyError – If config_name not found
Example
>>> email_config = get_field_config('email') >>> email_config.format 'email'