Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix stat input validation
  • Loading branch information
regalijan committed Mar 16, 2024
1 parent 5cf8063 commit 0fa0858
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions components/GameAppealCard.tsx
Expand Up @@ -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>
Expand Down

0 comments on commit 0fa0858

Please sign in to comment.