sodistorehome configurtaion minsoc error message disappeared after a valid input
This commit is contained in:
parent
5102678d35
commit
9dda68e084
|
|
@ -152,67 +152,33 @@ function SodistoreHomeConfiguration(props: SodistoreHomeConfigurationProps) {
|
|||
const handleChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
|
||||
switch (name) {
|
||||
// case 'minimumSoC':
|
||||
// if (
|
||||
// /[^0-9.]/.test(value) ||
|
||||
// isNaN(parseFloat(value)) ||
|
||||
// parseFloat(value) > 30 ||
|
||||
// parseFloat(value) < 10
|
||||
// ) {
|
||||
// SetErrorForField(name, true);
|
||||
// } else {
|
||||
// SetErrorForField(name, false);
|
||||
// }
|
||||
// break;
|
||||
case 'minimumSoC': {
|
||||
const numValue = parseFloat(value);
|
||||
if (name === 'minimumSoC') {
|
||||
const numValue = parseFloat(value);
|
||||
|
||||
// Check for invalid characters or non-numeric
|
||||
if (/[^0-9.]/.test(value) || isNaN(numValue)) {
|
||||
SetErrorForField(name, {
|
||||
hasError: true,
|
||||
message: 'Invalid number format',
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// Define device-based ranges
|
||||
// invalid characters or not a number
|
||||
if (/[^0-9.]/.test(value) || isNaN(numValue)) {
|
||||
SetErrorForField(name, 'Invalid number format');
|
||||
} else {
|
||||
const minsocRanges = {
|
||||
3: { min: 10, max: 30 },
|
||||
4: { min: 5, max: 100 },
|
||||
};
|
||||
|
||||
// Fallback range if device not listed
|
||||
const { min, max } = minsocRanges[device] || { min: 10, max: 30 };
|
||||
|
||||
if (numValue < min || numValue > max) {
|
||||
SetErrorForField(name, {
|
||||
hasError: true,
|
||||
message: `Value should be between ${min}-${max}%`,
|
||||
});
|
||||
SetErrorForField(name, `Value should be between ${min}-${max}%`);
|
||||
} else {
|
||||
SetErrorForField(name, { hasError: false, message: '' });
|
||||
// ✅ valid → clear error
|
||||
SetErrorForField(name, '');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'gridSetPoint':
|
||||
if (/[^0-9.]/.test(value) || isNaN(parseFloat(value))) {
|
||||
SetErrorForField(name, true);
|
||||
} else {
|
||||
SetErrorForField(name, false);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
setFormValues({
|
||||
...formValues,
|
||||
[name]: value
|
||||
});
|
||||
setFormValues(prev => ({
|
||||
...prev,
|
||||
[name]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
const handleTimeChargeDischargeChange = (name: string, value: any) => {
|
||||
|
|
@ -367,27 +333,37 @@ function SodistoreHomeConfiguration(props: SodistoreHomeConfigurationProps) {
|
|||
|
||||
|
||||
<div style={{ marginBottom: '5px' }}>
|
||||
{/*<TextField*/}
|
||||
{/* label={*/}
|
||||
{/* <FormattedMessage*/}
|
||||
{/* id="minimum_soc "*/}
|
||||
{/* defaultMessage="Minimum SoC (%)"*/}
|
||||
{/* />*/}
|
||||
{/* }*/}
|
||||
{/* name="minimumSoC"*/}
|
||||
{/* value={formValues.minimumSoC}*/}
|
||||
{/* onChange={handleChange}*/}
|
||||
{/* helperText={*/}
|
||||
{/* errors.minimumSoC ? (*/}
|
||||
{/* <span style={{ color: 'red' }}>*/}
|
||||
{/* Value should be between {device === 4 ? '5–100' : '10–30'}%*/}
|
||||
{/* </span>*/}
|
||||
{/* ) : (*/}
|
||||
{/* ''*/}
|
||||
{/* )*/}
|
||||
{/* }*/}
|
||||
{/* fullWidth*/}
|
||||
{/*/>*/}
|
||||
<TextField
|
||||
label={
|
||||
<FormattedMessage
|
||||
id="minimum_soc "
|
||||
defaultMessage="Minimum SoC (%)"
|
||||
/>
|
||||
}
|
||||
label="Minimum SoC (%)"
|
||||
name="minimumSoC"
|
||||
value={formValues.minimumSoC}
|
||||
onChange={handleChange}
|
||||
helperText={
|
||||
errors.minimumSoC ? (
|
||||
<span style={{ color: 'red' }}>
|
||||
Value should be between {device === 4 ? '5–100' : '10–30'}%
|
||||
</span>
|
||||
) : (
|
||||
''
|
||||
)
|
||||
}
|
||||
error={Boolean(errors.minimumSoC)}
|
||||
helperText={errors.minimumSoC}
|
||||
fullWidth
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: '5px' }}>
|
||||
|
|
|
|||
Loading…
Reference in New Issue