shouldShow static method

bool shouldShow(
  1. Map<String, dynamic>? conditional,
  2. Map<String, dynamic> formData
)

Evaluates whether a component should be shown based on its conditional logic.

Supports:

  • Conditions array: {show: true/false, conjunction: 'all'/'any', conditions: ...}
  • Simple conditionals: {when: 'field', eq: 'value', show: true/false}
  • JSONLogic: {json: {...}} format with standard JSONLogic operations

Parameters:

  • conditional: The conditional configuration from component.raw'conditional'
  • formData: The current form data to evaluate against

Returns true if the component should be shown, false otherwise.

Implementation

static bool shouldShow(Map<String, dynamic>? conditional, Map<String, dynamic> formData) {
  // No conditional means always show
  if (conditional == null || conditional.isEmpty) {
    return true;
  }

  // Check if this is a JSONLogic conditional
  if (conditional.containsKey('json')) {
    return _evaluateJSONLogic(conditional['json'], formData);
  }

  // Check if this is a custom JavaScript conditional (not supported)
  if (conditional.containsKey('custom')) {
    // JavaScript custom code is not supported in Dart
    // Log a warning and default to showing the component
    print('Warning: JavaScript custom conditionals are not supported. Component will be shown by default.');
    return true;
  }

  // Check if this is a conditions array format (newer Form.io format)
  if (conditional.containsKey('conditions') && conditional['conditions'] is List) {
    return _evaluateConditionsArray(conditional, formData);
  }

  // Otherwise, treat as a simple conditional
  return _evaluateSimpleConditional(conditional, formData);
}