Skip to content

Commit

Permalink
feat: max value accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharmyn28 committed Nov 7, 2024
1 parent bf5b38b commit 8171fea
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/components/field/MinimumLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ import { FieldSection } from './FieldSection'

export const MinimumLocation = ({ handleChange, settings, ...props }) => {
const handleValidInput = (e) => {
const inputValue = isNullUndefinedOrEmptyString(e.value)
? null
: Math.max(0, e.value).toString()
const inputValue = e.value

handleChange({
name: MINIMUM_LOCATION,
value: inputValue,
})
// Allow clearing the input to set the value to null
if (isNullUndefinedOrEmptyString(inputValue)) {
handleChange({ name: MINIMUM_LOCATION, value: null })
return
}

// Check if the value is a valid positive number within the range
const numericValue = Number(inputValue)
if (!isNaN(numericValue) && numericValue >= 1 && numericValue <= 99) {
handleChange({
name: MINIMUM_LOCATION,
value: numericValue.toString(),
})
}
}

return (
Expand All @@ -33,6 +41,7 @@ export const MinimumLocation = ({ handleChange, settings, ...props }) => {
onChange={(e) => handleValidInput(e)}
step="5"
min="5"
max="99"
{...props}
/>
</FieldSection>
Expand Down

0 comments on commit 8171fea

Please sign in to comment.