Best Practices

Forsta HX Platform - API Scripting Guide

Best Practices

⭐ Forsta Standard Coding Practices

  • Use Forsta methods for all data operations:
    • f('Qid').domainValues() to get all options
    • f('Qid').item(code).toBoolean() to check selections
    • f('Qid').item(code).toNumber() to get numeric values
    • f('Qid').set(value) to set values
    • f('Qid').get() to get values
  • Use jQuery only for DOM manipulation: .show(), .hide(), .addClass(), .find()
  • Loop through domainValues(): Always use for loop or forEach with .domainValues()
  • Clear hidden values: When hiding questions with jQuery, clear their data separately if needed
  • Use descriptive variable names: totalSpend not ts
  • Comment your logic: Especially calculations and business rules
  • Test all paths: Verify all conditional logic works correctly

Performance

  • Cache selectors in variables
  • Use event delegation
  • Minimize DOM manipulations
  • Debounce input events

Accessibility

  • Clear error messages
  • Use ARIA labels
  • Keyboard navigation
  • Screen reader friendly