Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(ui): add types, logic and defaults for min, max value of input component of form

Dinesht04157dbfd08a14
diff --git a/ui/src/components/SchemaForm/components/Input.tsx b/ui/src/components/SchemaForm/components/Input.tsx
index c0fd084c..3a2c0397 100644
--- a/ui/src/components/SchemaForm/components/Input.tsx
+++ b/ui/src/components/SchemaForm/components/Input.tsx
@@ -29,7 +29,8 @@ interface Props {
onChange?: (fd: Type.FormDataType) => void;
formData: Type.FormDataType;
readOnly: boolean;
- minValue?: number;
+ min?: number;
+ max?: number;
inputMode?:
| 'text'
| 'search'
@@ -48,7 +49,8 @@ const Index: FC<Props> = ({
onChange,
formData,
readOnly = false,
- minValue = 0,
+ min = 0,
+ max = 65355,
inputMode = 'text',
}) => {
const fieldObject = formData[fieldName];
@@ -73,7 +75,8 @@ const Index: FC<Props> = ({
placeholder={placeholder}
type={type}
value={fieldObject?.value || ''}
- min={minValue}
+ min={min}
+ max={max}
inputMode={inputMode}
onChange={handleChange}
disabled={readOnly}
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx
index 23b193b4..5bde2fdc 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -260,6 +260,8 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
enum: enumValues = [],
enumNames = [],
max_length = 0,
+ max = 65355,
+ min = 0,
} = properties[key];
const { 'ui:widget': widget = 'input', 'ui:options': uiOpt } =
uiSchema?.[key] || {};
@@ -374,6 +376,8 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
placeholder={
uiOpt && 'placeholder' in uiOpt ? uiOpt.placeholder : ''
}
+ min={min}
+ max={max}
fieldName={key}
onChange={onChange}
formData={formData}
@@ -408,9 +412,14 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
type={
uiOpt && 'inputType' in uiOpt ? uiOpt.inputType : 'text'
}
+ inputMode={
+ uiOpt && 'inputMode' in uiOpt ? uiOpt.inputMode : 'text'
+ }
placeholder={
uiOpt && 'placeholder' in uiOpt ? uiOpt.placeholder : ''
}
+ min={min}
+ max={max}
fieldName={key}
onChange={onChange}
formData={formData}
diff --git a/ui/src/components/SchemaForm/types.ts b/ui/src/components/SchemaForm/types.ts
index eaedf902..55cf8e99 100644
--- a/ui/src/components/SchemaForm/types.ts
+++ b/ui/src/components/SchemaForm/types.ts
@@ -49,6 +49,8 @@ export interface JSONSchema {
description?: string;
enum?: Array<string | boolean | number>;
enumNames?: string[];
+ min?: number;
+ max?: number;
default?: string | boolean | number | any[];
max_length?: number;
};