summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx')
-rw-r--r--sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx81
1 files changed, 37 insertions, 44 deletions
diff --git a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
index cf462052e..ac4afc1d9 100644
--- a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
+++ b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
@@ -19,59 +19,52 @@
import { ViewElementNumber } from "models/uiModels";
import { Tooltip, InputAdornment } from "@material-ui/core";
import * as React from 'react';
-import { baseProps } from "./baseProps";
+import { BaseProps } from "./baseProps";
import { IfWhenTextInput } from "./ifWhenTextInput";
import { checkRange } from "./verifyer";
-type numberInputProps = baseProps;
+type numberInputProps = BaseProps<number>;
export const UiElementNumber = (props: numberInputProps) => {
- const [error, setError] = React.useState(false);
- const [helperText, setHelperText] = React.useState("");
- const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
+ const [error, setError] = React.useState(false);
+ const [helperText, setHelperText] = React.useState("");
+ const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
- const element = props.value as ViewElementNumber;
+ const element = props.value as ViewElementNumber;
- const verifyValue = (data: string) => {
-
- if (data.trim().length > 0) {
- const num = Number(data);
- if (!isNaN(num)) {
- const result = checkRange(element, num);
- if (result.length > 0) {
- setError(true);
- setHelperText(result);
- } else {
- setError(false);
- setHelperText("");
- }
- } else {
- setError(true);
- setHelperText("Input is not a number.");
- }
- } else {
- setError(false);
- setHelperText("");
- }
-
- props.onChange(data);
+ const verifyValue = (data: string) => {
+ const num = Number(data);
+ if (!isNaN(num)) {
+ const result = checkRange(element, num);
+ if (result.length > 0) {
+ setError(true);
+ setHelperText(result);
+ } else {
+ setError(false);
+ setHelperText("");
+ }
+ } else {
+ setError(true);
+ setHelperText("Input is not a number.");
}
+ props.onChange(num);
+ }
- return (
- <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
- <IfWhenTextInput element={element} toogleTooltip={(val: boolean) => setTooltipVisibility(val)}
- spellCheck={false} autoFocus margin="dense"
- id={element.id} label={element.label} type="text" value={props.inputValue}
- style={{ width: 485, marginLeft: 20, marginRight: 20 }}
- onChange={(e: any) => { verifyValue(e.target.value) }}
- error={error}
- readOnly={props.readOnly}
- disabled={props.disabled}
- helperText={helperText}
- startAdornment={element.units != null ? <InputAdornment position="start">{element.units}</InputAdornment> : undefined}
- />
- </Tooltip>
- );
+ return (
+ <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
+ <IfWhenTextInput element={element} onChangeTooltipVisuability={setTooltipVisibility}
+ spellCheck={false} autoFocus margin="dense"
+ id={element.id} label={element.label} type="text" value={props.inputValue}
+ style={{ width: 485, marginLeft: 20, marginRight: 20 }}
+ onChange={(e) => { verifyValue(e.target.value) }}
+ error={error}
+ readOnly={props.readOnly}
+ disabled={props.disabled}
+ helperText={helperText}
+ startAdornment={element.units != null ? <InputAdornment position="start">{element.units}</InputAdornment> : undefined}
+ />
+ </Tooltip>
+ );
} \ No newline at end of file