Skip to content

Commit 1418745

Browse files
Dinesht04LinkinStars
authored andcommitted
feat(ui): add types, logic and defaults for min, max value of input component of form
1 parent 9bb87bf commit 1418745

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

ui/src/components/SchemaForm/components/Input.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ interface Props {
2929
onChange?: (fd: Type.FormDataType) => void;
3030
formData: Type.FormDataType;
3131
readOnly: boolean;
32-
minValue?: number;
32+
min?: number;
33+
max?: number;
3334
inputMode?:
3435
| 'text'
3536
| 'search'
@@ -48,7 +49,8 @@ const Index: FC<Props> = ({
4849
onChange,
4950
formData,
5051
readOnly = false,
51-
minValue = 0,
52+
min = 0,
53+
max = 65355,
5254
inputMode = 'text',
5355
}) => {
5456
const fieldObject = formData[fieldName];
@@ -73,7 +75,8 @@ const Index: FC<Props> = ({
7375
placeholder={placeholder}
7476
type={type}
7577
value={fieldObject?.value || ''}
76-
min={minValue}
78+
min={min}
79+
max={max}
7780
inputMode={inputMode}
7881
onChange={handleChange}
7982
disabled={readOnly}

ui/src/components/SchemaForm/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
260260
enum: enumValues = [],
261261
enumNames = [],
262262
max_length = 0,
263+
max = 65355,
264+
min = 0,
263265
} = properties[key];
264266
const { 'ui:widget': widget = 'input', 'ui:options': uiOpt } =
265267
uiSchema?.[key] || {};
@@ -374,6 +376,8 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
374376
placeholder={
375377
uiOpt && 'placeholder' in uiOpt ? uiOpt.placeholder : ''
376378
}
379+
min={min}
380+
max={max}
377381
fieldName={key}
378382
onChange={onChange}
379383
formData={formData}
@@ -408,9 +412,14 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
408412
type={
409413
uiOpt && 'inputType' in uiOpt ? uiOpt.inputType : 'text'
410414
}
415+
inputMode={
416+
uiOpt && 'inputMode' in uiOpt ? uiOpt.inputMode : 'text'
417+
}
411418
placeholder={
412419
uiOpt && 'placeholder' in uiOpt ? uiOpt.placeholder : ''
413420
}
421+
min={min}
422+
max={max}
414423
fieldName={key}
415424
onChange={onChange}
416425
formData={formData}

ui/src/components/SchemaForm/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface JSONSchema {
4949
description?: string;
5050
enum?: Array<string | boolean | number>;
5151
enumNames?: string[];
52+
min?: number;
53+
max?: number;
5254
default?: string | boolean | number | any[];
5355
max_length?: number;
5456
};

0 commit comments

Comments
 (0)