Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/javascript/forms/data-driven-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import defaultComponentMapper from './mappers/componentMapper';
import validatorMapper from './mappers/validatorMapper';
import SpyField from './spy-field';

Validators.messages = {
Expand Down Expand Up @@ -60,6 +61,7 @@ const MiqFormRenderer = ({
return (
<FormRender
componentMapper={{ ...componentMapper, 'spy-field': SpyField }}
validatorMapper={validatorMapper}
FormTemplate={MiqFormTemplate}
schema={{ fields: [...fields, { component: 'spy-field', name: 'spy-field', initialize }], ...schema }}
{...props}
Expand Down
12 changes: 12 additions & 0 deletions app/javascript/forms/mappers/validatorMapper.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { parseCondition, validatorMapper } from '@data-driven-forms/react-form-renderer';

const conditionalValidator = fn => ({ condition, ...schema }) => (value, allValues, meta) => (
!condition || parseCondition(condition, allValues).result ? fn(schema)(value, allValues, meta) : undefined
);

const mapper = Object.keys(validatorMapper).reduce((obj, key) => ({
...obj,
[key]: conditionalValidator(validatorMapper[key]),
}), {});

export default mapper;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"dependencies": {
"@carbon/icons-react": "~10.11.0",
"@carbon/themes": "~10.12.0",
"@data-driven-forms/pf3-component-mapper": "~2.8.13",
"@data-driven-forms/react-form-renderer": "~2.8.13",
"@data-driven-forms/pf3-component-mapper": "~2.8.23",
"@data-driven-forms/react-form-renderer": "~2.8.23",
"@manageiq/react-ui-components": "~0.11.70",
"@manageiq/ui-components": "~1.4.3",
"@pf3/select": "~1.12.6",
Expand Down