is - test if the value is equal

condition: {
when: 'Foo',
is: 'Bar',
}
// Foo == 'Bar' => true
// Foo == 'Not a Bar' => false

Is condition

To show field 2 type cat here!

import React from 'react';
import FormRenderer from '@data-driven-forms/react-form-renderer/form-renderer';
import componentTypes from '@data-driven-forms/react-form-renderer/component-types';
import TextField from '@data-driven-forms/mui-component-mapper/text-field';
import FormTemplate from '@data-driven-forms/mui-component-mapper/form-template';
const schema = {
title: 'Is condition',
fields: [
{
component: componentTypes.TEXT_FIELD,
name: 'field-1',
label: 'Field 1',
helperText: 'To show field 2 type cat here!',
},
{
component: componentTypes.TEXT_FIELD,
name: 'field-2',
label: 'Field 2',
initialValue: 'I am shown!',
isDisabled: true,
condition: { when: 'field-1', is: 'cat' },
},
],
};
const componentMapper = {
[componentTypes.TEXT_FIELD]: TextField,
};
const IsCondition = () => (
<div>
<FormRenderer FormTemplate={FormTemplate} componentMapper={componentMapper} schema={schema} onSubmit={console.log} />
</div>
);
IsCondition.displayName = 'Is condition';
export default IsCondition;

(value: any, config: condition object) => boolean

is also allows to use a custom function. This function receives the value of the when field as the first attribute and the condition config as the second argument.

condition: {
when: 'Foo',
is: (value, config) => calculateAge(value, config) > 18
}

Something went wrong.