mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Implement boolean and number fields
This commit is contained in:
@ -1,5 +1,13 @@
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Alert, Divider, Modal, ScrollArea, TextInput } from '@mantine/core';
|
import {
|
||||||
|
Alert,
|
||||||
|
Checkbox,
|
||||||
|
Divider,
|
||||||
|
Modal,
|
||||||
|
NumberInput,
|
||||||
|
ScrollArea,
|
||||||
|
TextInput
|
||||||
|
} from '@mantine/core';
|
||||||
import { Button, Center, Group, Loader, Stack, Text } from '@mantine/core';
|
import { Button, Center, Group, Loader, Stack, Text } from '@mantine/core';
|
||||||
import { useForm } from '@mantine/form';
|
import { useForm } from '@mantine/form';
|
||||||
import { IconAlertCircle } from '@tabler/icons-react';
|
import { IconAlertCircle } from '@tabler/icons-react';
|
||||||
@ -20,13 +28,12 @@ export type ApiFormFieldType = {
|
|||||||
name: string;
|
name: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
value?: any;
|
value?: any;
|
||||||
type?: string;
|
fieldType?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
icon?: ReactNode;
|
|
||||||
errors?: string[];
|
errors?: string[];
|
||||||
error?: any;
|
error?: any;
|
||||||
};
|
};
|
||||||
@ -59,14 +66,22 @@ function ApiFormField({
|
|||||||
return def;
|
return def;
|
||||||
}, [field, definitions]);
|
}, [field, definitions]);
|
||||||
|
|
||||||
switch (definition.type) {
|
switch (definition.fieldType) {
|
||||||
case 'url':
|
case 'url':
|
||||||
case 'string':
|
case 'string':
|
||||||
return <TextInput {...definition} />;
|
return <TextInput {...definition} />;
|
||||||
|
case 'boolean':
|
||||||
|
return <Checkbox radius="sm" {...definition} />;
|
||||||
|
case 'integer':
|
||||||
|
case 'decimal':
|
||||||
|
case 'float':
|
||||||
|
case 'number':
|
||||||
|
return <NumberInput radius="sm" {...definition} />;
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<Alert color="red" title="Error">
|
<Alert color="red" title="Error">
|
||||||
Unknown field type for field '{definition.name}': {definition.type}
|
Unknown field type for field '{definition.name}':{' '}
|
||||||
|
{definition.fieldType}
|
||||||
</Alert>
|
</Alert>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -194,10 +209,9 @@ export function ApiForm({
|
|||||||
label: field.label,
|
label: field.label,
|
||||||
description: field.help_text,
|
description: field.help_text,
|
||||||
value: field.value,
|
value: field.value,
|
||||||
type: field.type,
|
fieldType: field.type,
|
||||||
required: field.required,
|
required: field.required,
|
||||||
placeholder: field.placeholder,
|
placeholder: field.placeholder
|
||||||
icon: field.icon
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ export default function Home() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'virtual'
|
name: 'virtual'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'minimum_stock'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user