Advanced Conditional Form Validation

I have a question regarding advanced form validation and conditional field management. I’m currently aware only of basic validation features (primarily integer and text validation).

I’m trying to understand whether NocoBase already supports—or might soon support—more complex conditional validation logic. I believe this is partially addressed in Form Validation: Check new stock quantity before submit form, but the commercial plugin doesn’t deliver the requirements below - because it’s done post submit which is a horrendous user experience.


:vertical_traffic_light: Example Use Case: Conditional Form Fields

Here’s a simple illustration of the type of scenario I’m talking about:

Checkbox Field :white_check_mark: Dependent Fields :1234: Are Fields Required? :question:
:white_check_mark: Has Floor Floor Surface, Length, Width Yes (required)
:x: Has Floor (unchecked) Floor Surface (cleared), Length, Width No (optional)

Specifically:

  • When “Has Floor” is ticked:
    • The fields Floor Surface, Length, and Width must be filled out.
  • When “Has Floor” is not ticked:
    • The Floor Surface field is cleared and changed to read only.
    • Length and Width become optional fields (but users can still provide values).

:warning: Managing Conflicts (Precedence Rules)

Another complexity is handling conflicts when multiple conditions apply to the same field. For example:

  • One rule makes a field required.
  • Another rule makes the same field optional.

In such cases, we’d need a clear method to decide which condition applies:

  • Can we choose whether “most stringent” (required) or “least stringent” (optional) takes precedence?

:globe_with_meridians: Advanced Conditions Using Queries (Stretch Goal)

I’d also like the ability for field validation or conditional requirements to be based on the results of more advanced database queries involving multiple tables or collections.

For example, imagine the following scenario:

  • We have two tables:
Table: Areas :office: Table: ElectricalFitouts :electric_plug:
area_id fitout_id
area_name area_id (foreign key to Areas)
has_electrical (bool) num_outlets (integer)

We might require a field such as Electrical Feed Sizing (dropdown with load sizes) to be conditionally validated based on a computed value derived from these related tables. Specifically, we could perform a calculation such as:

“The selected electrical feed sizing must be greater than or equal to the nominal load, which is calculated as the total number of outlets multiplied by 1.2 (i.e., a 20% additional capacity margin).”

This could be expressed as an SQL/Postgres query similar to:

SELECT 
    a.area_id,
    a.area_name,
    ef.total_outlets,
    (ef.total_outlets * 1.2) AS nominal_load
FROM 
    Areas a
INNER JOIN (
    SELECT 
        area_id, 
        SUM(num_outlets) AS total_outlets
    FROM 
        ElectricalFitouts
    GROUP BY 
        area_id
) ef ON a.area_id = ef.area_id
WHERE 
    a.has_electrical = true;
  • The form’s conditional validation logic would then compare the user’s selection from the Electrical Feed Sizing dropdown against the computed nominal_load.
  • If the chosen sizing is below the calculated nominal_load, validation should fail and prompt the user to select a higher rating.

This advanced functionality would greatly enhance the robustness of data validation by directly linking form behaviour to live database computations, ensuring accuracy and consistency across complex data scenarios.


:gear: Technical Considerations (If Feature Isn’t Currently Available):

If this isn’t an existing feature, here are some considerations for potential implementation:

  • Logical Operators:

    • Allow combining multiple conditions logically (AND, OR).
  • User Interface:

    • Provide a clear and intuitive UI so administrators can easily configure these conditional rules without confusion.
  • Performance Implications:

    • Address performance concerns, especially with query-based conditional logic.
  • Extensibility & Customisation:

    • Ideally, support managing these rules through plugins, custom scripts, or APIs for maximum flexibility.

:pushpin: Why is this important? (User Experience & Data Integrity)

Currently, conditional validation relies on a commercial plugin providing a “pre-action trigger” that checks only when the user attempts to submit the form. Unfortunately, this creates a frustrating user experience:

  • Users fill out a form entirely, submit it, and then receive validation errors after submission due to backend database checks.
  • This forces the user to repeatedly correct and resubmit the form, resulting in a tedious and inefficient workflow.

Real-time conditional validation based on dynamic data queries (like the example above) is critical because it:

  • Provides instant feedback, guiding the user clearly as they fill in the form.
  • Ensures data entered aligns with current database states and computed requirements.
  • Significantly enhances the overall user experience, making forms more intuitive, responsive, and efficient.
  • Reduces errors and increases data integrity by catching and correcting issues before submission.

Ultimately, integrating advanced conditional validation directly into NocoBase would drastically improve both user satisfaction and the accuracy of collected data.


:thinking: My Questions to the NocoBase Community & Developers:

  • Does NocoBase already have this kind of conditional validation and management?

    • If so, could anyone guide me through how it’s done?
  • If this feature doesn’t exist, would the NocoBase team consider this as a potential enhancement?

We are developing Event flow, which will (but not necessarily in the first version) meet your needs.