Skip to content

Add Support for Conditional Validation with cond:field=value Syntax #3

@abmercy035

Description

@abmercy035

We need to implement conditional validation to allow rules to be applied only when certain conditions are met. This will enable more complex validation scenarios where some fields are only required or validated based on the values of other fields.

Problem to Solve:
Currently, all validation rules are applied unconditionally, which doesn't work for forms with conditional fields or business logic that depends on specific field values.

Acceptance Criteria:

  • Implement cond:field=value syntax to conditionally apply rules
  • Support for multiple conditions with AND/OR logic
  • Support for comparison operators (=, !=, >, <, >=, <=)
  • Support for nested field references in conditions
  • Add comprehensive tests for conditional validation
  • Update documentation with examples

Implementation Suggestions:

  • Add a condition parser in the rule executor
  • Implement a condition evaluator that checks if conditions are met before applying rules
  • Support both simple equality and more complex comparisons

Example Usage:

const rules = [
  "shippingAddress-string-cond:needsShipping=true",
  "cardNumber-string-16-cond:paymentMethod=credit",
  "cvv-number-3-cond:paymentMethod=credit",
  "accountNumber-string-cond:paymentMethod=bank"
];

Labels: enhancement, conditional-validation, feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions