Common Gotchas & Pitfalls

Forsta HX Platform - API Scripting Guide

Common Gotchas & Pitfalls

Common Mistakes

  • Forgetting to clear hidden questions - Always f(qid).hide().val("")
  • Not checking if question exists - Use if(f(qid).length > 0)
  • Hard-coding question IDs in loops - Store in arrays instead
  • Not handling mobile devices - Test on actual devices, not just dev tools
  • Ignoring async operations - Use promises/callbacks properly
  • Not validating on both client and server - Client validation can be bypassed
  • Forgetting about page refresh - Implement auto-save for long surveys
  • Not testing skip logic thoroughly - Test all conditional paths

Avoiding Common Errors:

// ❌ BAD - No null check
var age = f(AQ1).val();
if(age > 18) { }  // May fail if AQ1 doesn't exist

// ✅ GOOD - Check existence first
if(f(AQ1).length && f(AQ1).val()) {
    var age = parseInt(f(AQ1).val());
    if(age > 18) { }
}

// ❌ BAD - Not clearing hidden questions
f(BQ1).hide();

// ✅ GOOD - Clear when hiding
f(BQ1).hide().val("");

// ❌ BAD - Hardcoded IDs
f(AQ1).hide();
f(AQ2).hide();
f(AQ3).hide();

// ✅ GOOD - Use arrays
['AQ1', 'AQ2', 'AQ3'].forEach(function(qid) {
    f(qid).hide().val("");
});