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 NumericRangeField from '../rjsf/custom_widgets/NumericRangeField/NumericRangeField';
|
||||
import ObjectFieldRestrictedGridTemplate from '../rjsf/custom_templates/ObjectFieldRestrictGridTemplate';
|
||||
import { matchNumberRegex } from '../helpers';
|
||||
|
||||
enum DateCheckType {
|
||||
minimum = 'minimum',
|
||||
|
@ -264,6 +265,12 @@ export default function CustomForm({
|
|||
) {
|
||||
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 (
|
||||
formDataToCheck[propertyKey].min <
|
||||
jsonSchema.properties[propertyKey].minimum
|
||||
|
|
|
@ -9,6 +9,8 @@ export const doNothing = () => {
|
|||
return undefined;
|
||||
};
|
||||
|
||||
export const matchNumberRegex = /^[0-9,.]*$/;
|
||||
|
||||
// https://www.30secondsofcode.org/js/s/slugify
|
||||
export const slugifyString = (str: string) => {
|
||||
return str
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
import React from 'react';
|
||||
import { TextInput } from '@carbon/react';
|
||||
import { getCommonAttributes } from '../../helpers';
|
||||
import { matchNumberRegex } from '../../../helpers';
|
||||
|
||||
// Example jsonSchema - NOTE: the "min" and "max" properties are special names and must be used:
|
||||
// "compensation":{
|
||||
|
@ -66,6 +67,11 @@ export default function NumericRangeField({
|
|||
// and a decimal point if needed. For example, 1000 will become 1,000
|
||||
// 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, '');
|
||||
|
||||
if (numberStringNoCommas) {
|
||||
|
|
Loading…
Reference in New Issue