Custom Conditional

Start of documentation content

Allows custom conditional rules in JavaScript with the onConditional prop.

Intro

Any <Conditional> or <Page rules={...}> can have additional custom logic provided. The function can be sync or async, and it returns undefined, true, or false.

Use of onConditional

import { Formally } from 'formally';

<Formally
  onConditional={async ({
    conditionResult,
    formallyData,
    valuesToBeTested,
    allValues,
    rules,
    locale,
  }) => {
    // your custom conditional code goes here...
    /**
     You can return either...
     * @returns `undefined` rules can't be evaluated because there's not enough
                form data to evaluate answers, so whether it would pass is ambiguous
     * @returns `true` rules evaluate true and we have enough form data to evaluate answers
     * @returns `false` rules evaluate false and we have enough form data to evaluate answers
     **/
  }}
/>;