Skip to content

Commit

Permalink
feat: adjusted grade field validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Inferato committed Oct 23, 2023
1 parent ba9bd46 commit 62656ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ const useAdjustedGradeInputData = () => {
const hintText = possibleGrade && ` ${getLocalizedSlash()} ${possibleGrade}`;

const onChange = ({ target }) => {
setModalState({ adjustedGradeValue: target.value });
let adjustedGradeValue;
switch (true) {
case target.value < 0:
adjustedGradeValue = 0;
break;
case possibleGrade && target.value > possibleGrade:
adjustedGradeValue = possibleGrade;
break;
default:
adjustedGradeValue = target.value;
}
setModalState({ adjustedGradeValue });
};

return {
value,
onChange,
hintText,
possibleGrade,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export const AdjustedGradeInput = () => {
value,
onChange,
hintText,
possibleGrade,
} = useAdjustedGradeInputData();
return (
<span>
<Form.Control
type="text"
type="number"
name="adjustedGradeValue"
min="0"
max={possibleGrade ? possibleGrade : ''}
value={value}
onChange={onChange}
/>
Expand Down

0 comments on commit 62656ce

Please sign in to comment.