Skip to main content

Autocomplete Widget Documentation

Overviewโ€‹

The Autocomplete widget provides a dynamic dropdown input with real-time search functionality. It allows users to search and select values from a remote data source such as collections, reports, or external databases. The widget supports both single and multiple selection modes with customizable filtering and validation.

Autocomplete Widget

Basic Configurationโ€‹

Widget Propertiesโ€‹

Name and Modelโ€‹

  • Name: Display label for the widget
  • Variable/Model: The variable name that will store the selected value(s)

Data Type Supportโ€‹

The autocomplete widget can handle various data types and automatically formats the selected values based on the configured label and value properties.

Data Source Configurationโ€‹

Data Sourcesโ€‹

Connect to a database collection:

  • Collection: Select from available collections
  • Query: Define filtering criteria using MongoDB-style queries
  • Sort By: Configure sorting by field name and direction (-1 for descending, 1 for ascending)
  • Limit: Set maximum number of results to display
Data Source

Data Mappingโ€‹

Label and Value Propertiesโ€‹

Configure how data is displayed and stored:

  • Label Property: Field used for display text (e.g., name, title)
  • Value Property: Field used for the stored value (e.g., _id, code)
Data Mapping

Query Configurationโ€‹

Basic Queriesโ€‹

Use the query editor to define filtering criteria:

For Collections (MongoDB-style):

Query

Advanced Queries with Variablesโ€‹

Reference form variables in queries:

Queries with Variables

Selection Optionsโ€‹

Single vs Multiple Selectionโ€‹

  • Multiple: Enable to allow selection of multiple values
  • Clearable: Allow users to clear the selection
  • Filterable: Enable real-time search filtering (enabled by default for autocomplete)
Multiple Selection

Default Valuesโ€‹

Set initial values for the widget:

  • Single Selection: Provide a single default value
  • Multiple Selection: Provide an array of default values
Default Values

Validation Configurationโ€‹

Screen-based Validationโ€‹

Configure widget behavior across different screens:

Available Statesโ€‹

  • Available: Widget is rendered on the screen
  • Visible: Widget is visible to users
  • Required: Field must be filled before form submission
  • Disabled: Widget is read-only

Validation Modesโ€‹

  • Simple Mode: Use boolean values for each state
  • Advanced Mode: Use JavaScript expressions for dynamic validation

Example advanced validation:

Validation Modes

Validation Rulesโ€‹

Add custom validation rules with the Rules configuration:

Available Rule Typesโ€‹

  • Required: Field must have a value
  • Min Length: Minimum number of characters
  • Max Length: Maximum number of characters
  • Pattern: Regular expression validation
  • Custom: JavaScript validation function

Rule Configurationโ€‹

Rule Configuration

Event Handlingโ€‹

On Click Eventsโ€‹

Configure actions when users interact with the widget:

Event Dataโ€‹

The onClick event provides access to:

  • SF_input: Object containing:
    • value: Selected value(s)
    • SF_data: Complete selected object(s)
    • SF_currentIndex: Loop index (if within a loop)

Action Configurationโ€‹

Use the action editor to define JavaScript functions:

Action Configuration

Styling and Layoutโ€‹

Basic Stylingโ€‹

  • Placeholder: Text displayed when no selection is made
  • Width: Widget width (CSS units: px, %, em, etc.)
  • Class Names: CSS classes for custom styling

Dynamic Classesโ€‹

Use the dynamic classes feature for conditional styling:

Dynamic Classes
{
"error": "{{hasValidationError}}",
"highlighted": "{{isImportant}}",
"disabled": "{{!isEditable}}"
}

Advanced Featuresโ€‹

Remote Search Configurationโ€‹

The autocomplete widget automatically configures remote search with:

  • Debounced Search: Optimized search performance
  • Minimum Query Length: Prevents excessive API calls
  • Result Caching: Improves user experience

Data Refreshโ€‹

The widget automatically refreshes data when:

  • Search query changes
  • Parent form variables change
  • Widget gains focus

Performance Optimizationโ€‹

  • Lazy Loading: Data is loaded only when needed
  • Result Limiting: Default limit of 10 results for optimal performance
  • Query Optimization: Efficient database queries with indexing support

Integration Examplesโ€‹

Basic Product Selectionโ€‹

Product Selection
Product Selection

Troubleshootingโ€‹

Common Issuesโ€‹

No Results Displayedโ€‹

  • Verify collection/database connection
  • Check query syntax
  • Ensure proper field mapping
  • Verify user permissions

Slow Performanceโ€‹

  • Add database indexes for searched fields
  • Reduce result limit
  • Optimize query filters
  • Check network connectivity

Validation Errorsโ€‹

  • Verify required field configuration
  • Check validation rule syntax
  • Ensure proper event handling
  • Test with different data types

Best Practicesโ€‹

  1. Query Optimization: Use specific filters to reduce result sets
  2. Field Mapping: Choose descriptive labels and unique values
  3. Error Handling: Provide clear validation messages
  4. User Experience: Set appropriate placeholders and defaults
  5. Performance: Use pagination for large datasets

API Referenceโ€‹

Widget Propertiesโ€‹

  • id: Unique widget identifier
  • model: Data model binding
  • options: Configuration object containing all widget settings
  • validation: Screen-based validation rules
  • events: Event handler configurations

Methodsโ€‹

  • refresh(keyword): Manually refresh data with optional search term
  • setLabels(value): Update display labels based on selected values
  • clearValue(): Clear current selection
  • setValue(value): Programmatically set widget value

Eventsโ€‹

  • @change: Triggered when selection changes
  • @focus: Triggered when widget gains focus
  • @blur: Triggered when widget loses focus