Fix stat input validation

This commit is contained in:
Regalijan 2024-03-16 02:17:22 -04:00
parent 5cf80639ab
commit 0fa0858a3c
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -118,22 +118,24 @@ export default function (props: GameAppealProps & { port?: MessagePort }) {
const value = (e.target as EventTarget & { value: string })
.value;
return (
Boolean(value.match(/^-?\d{0,3}$/)) ||
value === "-" ||
!value
);
if (value !== "-" && value && !value.match(/^-?\d{0,3}$/))
e.preventDefault();
}}
onChange={(e) => setPercentage(parseInt(e.target.value))}
pattern="/^-?\d{0,3}$/"
placeholder="Reduction factor"
/>
<br />
<Text>Stat multiplication factors:</Text>
<br />
<UnorderedList>
<ListItem>Money: {Math.min(0.1 * percentage, 1)}</ListItem>
<ListItem>Parts: {Math.min(0.6 * percentage, 1)}</ListItem>
<ListItem>Derby Wins: {Math.min(0.6 * percentage, 1)}</ListItem>
<Text alignSelf="start">Stat multiplication factors:</Text>
<UnorderedList alignSelf="start">
<ListItem>
Money: {Math.min(0.1 * percentage, 1).toFixed(2)}
</ListItem>
<ListItem>
Parts: {Math.min(0.6 * percentage, 1).toFixed(2)}
</ListItem>
<ListItem>
Derby Wins: {Math.min(0.6 * percentage, 1).toFixed(2)}
</ListItem>
</UnorderedList>
</VStack>
</ModalBody>