Skip to content

Commit

Permalink
NCL-8162 Add async + multi-field validation demo
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikk0123 committed Oct 24, 2023
1 parent 2596216 commit e3ae6cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/DemoPage/DemoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ import mockBuildData from './data/mock-build-data.json';

const buildRes: Build[] = mockBuildData;

const validateMultipleFields = (fieldValues: IFieldValues): boolean => {
return !!fieldValues.inputFieldA && !!fieldValues.version;
};

const fieldConfigs = {
inputFieldA: {
isRequired: true,
validators: [
{ validator: validateMultipleFields, errorMessage: 'inputFieldA and version must be defined.', relatedFields: ['version'] },
{ validator: minLength(2), errorMessage: 'Text must be at least two characters long.' },
{
validator: maxLength(10),
Expand All @@ -74,6 +79,13 @@ const fieldConfigs = {
},
version: {
isRequired: true,
validators: [
{
validator: validateMultipleFields,
errorMessage: 'version and inputFieldA must be defined.',
relatedFields: ['inputFieldA'],
},
],
},
} satisfies IFieldConfigs;

Expand Down Expand Up @@ -375,6 +387,7 @@ export const DemoPage = () => {
{...register<string>(productMilestoneEntityAttributes.version.id, {
...fieldConfigs.version,
validators: [
...fieldConfigs.version.validators,
{
asyncValidator: (value) =>
serviceContainerValidateProductMilestone.run({
Expand Down

0 comments on commit e3ae6cb

Please sign in to comment.