Text Field Controller

A Text Field Controller is a special variable type that manages user input in text fields. It allows you to programmatically set, clear, or manipulate the text content of input fields, enabling dynamic form interactions and validation.

Supported Widgets

The Text Field Controller can be used with:

  • Text Form Field

When to Use

Use a Text Field Controller when you need to:

  • Programmatically set or clear text field values

  • Pre-fill forms with data

  • Reset forms after submission

  • Implement autocomplete or suggestions

  • Validate and modify input programmatically

  • Synchronize text across multiple fields

Creating a Text Field Controller

  1. Navigate to Variables in your project

  2. Click Add Variable

  3. Select Text Field Controller as the type

  4. Give it a descriptive name (e.g., emailController, searchController)

Binding to Widgets

Text Form Field Example

Controller Methods

Use the Control Object action to invoke these methods on the controller.

setValue

Sets the text field's value programmatically.

Parameter
Type
Description

text

String

The string to set as the field value

Example Use Cases:

  • Pre-fill with saved data: text: ${savedEmail}

  • Set default value: text: "[email protected]"

  • Copy from another field: text: ${otherFieldValue}

When to Use:

  • Loading saved form data

  • Implementing autocomplete

  • Copying values between fields

  • Setting default values


clear

Clears the text field, removing all content.

No parameters required.

Example Use Cases:

  • Reset form after submission

  • Clear search field

  • Remove invalid input

When to Use:

  • After successful form submission

  • Reset button functionality

  • Clearing invalid input


Common Use Cases

1. Pre-filling Forms with Saved Data

Load previously saved data into form fields.

Setup:

Implementation:

2. Reset Form After Submission

Clear all form fields after successful submission.

3. Search Field with Clear Button

Implement a search input with a clear button.

4. Autocomplete Implementation

Set field value when user selects from suggestions.

5. Copy Value to Another Field

Copy content from one field to another.

6. Format Input on Blur

Format input when user leaves the field.

Best Practices

  • One controller per field: Each Text Form Field should have its own controller

  • Use descriptive names: Name controllers after the field purpose (emailController, passwordController)

  • Store values separately: Use a separate variable to store the field value for easier access in logic

  • Clear on success: Clear form fields after successful submission for better UX

  • Validate before setting: Validate data before using setValue to avoid setting invalid values

  • Handle empty states: Check for null or undefined before setting values

  • Provide feedback: Show toast or message after clearing or setting values programmatically

Common Patterns

Load Saved Data

Clear All Fields

Clear After Success

Set from Selection

Conditional Clear

Troubleshooting

Controller Not Working

  • Ensure the controller variable is properly created

  • Check that the controller is bound to the Text Form Field using ${controllerName}

  • Verify you're using the correct controller reference

Value Not Updating in UI

  • Ensure the Text Form Field is bound to the controller

  • Check that the setValue action is being triggered

  • Verify the text value is a valid string

Clear Not Working

  • Confirm the controller is properly bound

  • Check that the clear method is being invoked correctly

  • Ensure no other actions are resetting the value immediately after

Last updated