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