mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-03-01 09:30:46 +00:00
numeric-range-check-for-num (#1451)
* check to ensure the value entered in a numeric range is a number * save the regex number matcher so it can be used in multiple places w/ burnettk --------- Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
1f056089f4
commit
40af8809a1
@ -10,6 +10,7 @@ import TypeaheadWidget from '../rjsf/custom_widgets/TypeaheadWidget/TypeaheadWid
|
|||||||
import MarkDownFieldWidget from '../rjsf/custom_widgets/MarkDownFieldWidget/MarkDownFieldWidget';
|
import MarkDownFieldWidget from '../rjsf/custom_widgets/MarkDownFieldWidget/MarkDownFieldWidget';
|
||||||
import NumericRangeField from '../rjsf/custom_widgets/NumericRangeField/NumericRangeField';
|
import NumericRangeField from '../rjsf/custom_widgets/NumericRangeField/NumericRangeField';
|
||||||
import ObjectFieldRestrictedGridTemplate from '../rjsf/custom_templates/ObjectFieldRestrictGridTemplate';
|
import ObjectFieldRestrictedGridTemplate from '../rjsf/custom_templates/ObjectFieldRestrictGridTemplate';
|
||||||
|
import { matchNumberRegex } from '../helpers';
|
||||||
|
|
||||||
enum DateCheckType {
|
enum DateCheckType {
|
||||||
minimum = 'minimum',
|
minimum = 'minimum',
|
||||||
@ -264,6 +265,12 @@ export default function CustomForm({
|
|||||||
) {
|
) {
|
||||||
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!formDataToCheck[propertyKey].min.toString().match(matchNumberRegex) ||
|
||||||
|
!formDataToCheck[propertyKey].max.toString().match(matchNumberRegex)
|
||||||
|
) {
|
||||||
|
errors[propertyKey].addError('must have valid numbers');
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
formDataToCheck[propertyKey].min <
|
formDataToCheck[propertyKey].min <
|
||||||
jsonSchema.properties[propertyKey].minimum
|
jsonSchema.properties[propertyKey].minimum
|
||||||
|
@ -9,6 +9,8 @@ export const doNothing = () => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const matchNumberRegex = /^[0-9,.]*$/;
|
||||||
|
|
||||||
// https://www.30secondsofcode.org/js/s/slugify
|
// https://www.30secondsofcode.org/js/s/slugify
|
||||||
export const slugifyString = (str: string) => {
|
export const slugifyString = (str: string) => {
|
||||||
return str
|
return str
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { TextInput } from '@carbon/react';
|
import { TextInput } from '@carbon/react';
|
||||||
import { getCommonAttributes } from '../../helpers';
|
import { getCommonAttributes } from '../../helpers';
|
||||||
|
import { matchNumberRegex } from '../../../helpers';
|
||||||
|
|
||||||
// Example jsonSchema - NOTE: the "min" and "max" properties are special names and must be used:
|
// Example jsonSchema - NOTE: the "min" and "max" properties are special names and must be used:
|
||||||
// "compensation":{
|
// "compensation":{
|
||||||
@ -66,6 +67,11 @@ export default function NumericRangeField({
|
|||||||
// and a decimal point if needed. For example, 1000 will become 1,000
|
// and a decimal point if needed. For example, 1000 will become 1,000
|
||||||
// or 1000.5 will become 1,000.5
|
// or 1000.5 will become 1,000.5
|
||||||
|
|
||||||
|
// if it does not look like a number then just return it
|
||||||
|
if (!numberString.match(matchNumberRegex)) {
|
||||||
|
return numberString;
|
||||||
|
}
|
||||||
|
|
||||||
const numberStringNoCommas = numberString.replace(/,/g, '');
|
const numberStringNoCommas = numberString.replace(/,/g, '');
|
||||||
|
|
||||||
if (numberStringNoCommas) {
|
if (numberStringNoCommas) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user