Observable Value
Learn how to use Observable values (like `BehaviorSubject` or `Observable`) in form inputs.
Overview
Use Case 1: Reactive Field with BehaviorSubject
Scenario
Configuration
import { BehaviorSubject } from 'rxjs';
import { FormInput, FormInputType } from '@tradinos/cms-frontend-form';
export class ProjectService extends EntityService<Project> {
// Create a BehaviorSubject to hold the slug value
public slugText$ = new BehaviorSubject<string>('');
override manualInputsFn = (project?: Project) => {
return [
{
key: 'name',
inputType: FormInputType.text,
value: project?.name,
onChange: (value: string) => {
// Update the slug Observable when name changes
this.slugText$.next(value.toLowerCase());
}
},
{
key: 'slug',
inputType: FormInputType.text,
value: this.slugText$, // Use Observable as value
},
] as FormInput<Project>[];
}
}Example from Codebase
Parameters Explained
Parameter
Type
Description
Required
How it Works
Use Case 2: Initializing Observable with Existing Value
Scenario
Configuration
How it Works
Use Case 3: Multiple Dependent Fields
Scenario
Configuration
Complete Examples
Example 1: Auto-Generated Slug from Name
Example 2: Calculated Field
Example 3: Conditional Field Updates
Comparison Table
Value Type
Use Case
Example
Reactive
Best Practices
Common Patterns
Pattern 1: Auto-Generated Slug
Pattern 2: Calculated Totals
Pattern 3: Conditional Formatting
Related Documentation
Summary
Last updated