Skip to content
Merged
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: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/validation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@user-office-software/duo-validation",
"version": "5.1.18",
"version": "5.1.19",
"description": "Duo frontend and backend validation in one place.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
35 changes: 34 additions & 1 deletion packages/validation/src/Questionary/interval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as Yup from 'yup';

export const intervalQuestionValidationSchema = (field: any) => {
export const intervalQuestionValidationSchema = (
field: any,
NumberValueConstraint: any
) => {
const config = field.config;

let minSchema = Yup.number().transform((value) =>
Expand All @@ -15,6 +18,36 @@ export const intervalQuestionValidationSchema = (field: any) => {
maxSchema = maxSchema.required('This is a required field');
}

switch (config.numberValueConstraint) {
case NumberValueConstraint.ONLY_NEGATIVE:
minSchema = minSchema.negative('Value must be a negative number');
maxSchema = maxSchema.negative('Value must be a negative number');
break;

case NumberValueConstraint.ONLY_POSITIVE:
minSchema = minSchema.positive('Value must be a positive number');
maxSchema = maxSchema.positive('Value must be a positive number');
break;

case NumberValueConstraint.ONLY_NEGATIVE_INTEGER:
minSchema = minSchema
.integer('Value must be negative whole number')
.negative('Value must be negative whole number');
maxSchema = maxSchema
.integer('Value must be negative whole number')
.negative('Value must be negative whole number');
break;

case NumberValueConstraint.ONLY_POSITIVE_INTEGER:
minSchema = minSchema
.integer('Value must be positive whole number')
.positive('Value must be a positive whole number');
maxSchema = maxSchema
.integer('Value must be positive whole number')
.positive('Value must be a positive whole number');
break;
}

let unitSchema = Yup.object().nullable();

// available units are specified and the field is required
Expand Down