2
0
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:
Oliver Walters
2023-07-27 15:32:02 +10:00
parent f1ddebebdb
commit fd8621fae4
2 changed files with 25 additions and 8 deletions

View File

@ -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
}); });
} }

View File

@ -31,6 +31,9 @@ export default function Home() {
}, },
{ {
name: 'virtual' name: 'virtual'
},
{
name: 'minimum_stock'
} }
]; ];