Adding a price widget
This commit is contained in:
33
gui/app/src/common/crud/widgets/bgfc-price.tsx
Normal file
33
gui/app/src/common/crud/widgets/bgfc-price.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { WidgetProps } from "@rjsf/utils";
|
||||
import { NumericFormat } from "react-number-format";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import {InputAdornment} from "@mui/material";
|
||||
|
||||
export const BgfcPriceWidget = (props: WidgetProps) => {
|
||||
const { inputRef, onChange, ...other } = props;
|
||||
|
||||
return (
|
||||
<NumericFormat
|
||||
customInput={TextField}
|
||||
getInputRef={inputRef}
|
||||
onValueChange={values => {
|
||||
onChange({
|
||||
target: {
|
||||
name: props.name,
|
||||
value: values.value
|
||||
}
|
||||
});
|
||||
}}
|
||||
slotProps={{
|
||||
input: {
|
||||
startAdornment: <InputAdornment position="end">$</InputAdornment>,
|
||||
endAdornment: <InputAdornment position="start">€</InputAdornment>
|
||||
},
|
||||
}}
|
||||
valueIsNumericString={true}
|
||||
fixedDecimalScale={true}
|
||||
decimalScale={2}
|
||||
defaultValue={0}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -2,13 +2,16 @@ import TextWidget from "@rjsf/core/lib/components/widgets/TextWidget";
|
||||
import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from "@rjsf/utils";
|
||||
|
||||
import { ForeignKeyWidget } from "./foreign-key";
|
||||
import {BgfcPriceWidget} from "./bgfc-price";
|
||||
|
||||
export default function CrudTextWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
||||
props: WidgetProps<T, S, F>
|
||||
) {
|
||||
if (props.schema.hasOwnProperty("foreign_key")) {
|
||||
return (<ForeignKeyWidget {...props} />);
|
||||
}else {
|
||||
} else if (props.schema.hasOwnProperty("format") && props.schema.format == "price-bgdc") {
|
||||
return (<BgfcPriceWidget {...props} />);
|
||||
} else {
|
||||
return (<TextWidget {...props} />);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user