Add conditional validation detection to int and float inputs
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 1 Oct 2018 08:12:30 +0000 (10:12 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 1 Oct 2018 08:12:30 +0000 (10:12 +0200)
Feature #13863

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/views/run-process-panel/inputs/float-input.tsx
src/views/run-process-panel/inputs/int-input.tsx

index 664425d3aefa33c0b273850becc4ea74fe6313ef..f6fffedcd4ce8edc55cb05bdedc1cb471675931e 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { getInputLabel, FloatCommandInputParameter } from '~/models/workflow';
+import { getInputLabel, FloatCommandInputParameter, isRequiredInput } from '~/models/workflow';
 import { Field, WrappedFieldProps } from 'redux-form';
 import { TextField } from '~/components/text-field/text-field';
 import { isNumber } from '~/validators/is-number';
@@ -17,8 +17,10 @@ export const FloatInput = ({ input }: FloatInputProps) =>
         component={DecimalInput}
         parse={parseFloat}
         format={value => isNaN(value) ? '' : JSON.stringify(value)}
-        validate={[isNumber]} />;
-
+        validate={[
+            isRequiredInput(input)
+                ? isNumber
+                : () => undefined,]} />;
 
 class DecimalInput extends React.Component<WrappedFieldProps & { label?: string }> {
     state = {
index 5b6f95dbcbc8f1b176edbfc68eee51ef5ded9074..60a49b61f5295dfb678d9dba28aee79f5206e56f 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { IntCommandInputParameter, getInputLabel } from '~/models/workflow';
+import { IntCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow';
 import { Field } from 'redux-form';
 import { TextField } from '~/components/text-field/text-field';
 import { isInteger } from '~/validators/is-integer';
@@ -18,5 +18,9 @@ export const IntInput = ({ input }: IntInputProps) =>
         component={TextField}
         parse={value => parseInt(value, 10)}
         format={value => isNaN(value) ? '' : JSON.stringify(value)}
-        validate={[isInteger]} />;
+        validate={[
+            isRequiredInput(input)
+                ? isInteger
+                : () => undefined,
+        ]} />;