Skip to content

Commit

Permalink
[fix]: restrict negative age, add age input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sanam2405 committed Feb 1, 2024
1 parent b0ffe29 commit 4baaca9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion frontend/src/components/FriendsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ function FriendsPage() {
const [college, setCollege] = useState('Jadavpur University')

const handleAgeChange = event => {
setAge(event.target.value)
const inputValue = parseFloat(event.target.value)
const newAge = inputValue <= 0 || inputValue > 125 ? 1 : inputValue

This comment has been minimized.

Copy link
@ciphercoder1999

ciphercoder1999 Apr 13, 2024

Contributor

why assuming people cannot live more than 125 years?

setAge(newAge)
}

const handleGenderChange = event => {
setGender(event.target.value)
}
Expand Down Expand Up @@ -305,6 +308,9 @@ function FriendsPage() {
id='outlined-number'
label='Required'
type='number'
InputProps={{
inputProps: { min: 1, max: 125 },
}}
InputLabelProps={{
shrink: true,
}}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function Map() {
const [sliderValue, setSliderValue] = useState(50)

const handleAgeChange = event => {
setAge(event.target.value)
const inputValue = parseFloat(event.target.value)
const newAge = inputValue <= 0 || inputValue > 125 ? 1 : inputValue
setAge(newAge)
}
const handleGenderChange = event => {
setGender(event.target.value)
Expand Down Expand Up @@ -434,6 +436,9 @@ function Map() {
type='number'
value={age}
onChange={handleAgeChange}
InputProps={{
inputProps: { min: 1, max: 125 },
}}
InputLabelProps={{
shrink: true,
}}
Expand Down

0 comments on commit 4baaca9

Please sign in to comment.