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 authored and dyudyunov committed Feb 7, 2024
1 parent acdad5a commit e3aa838
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 || ''}
value={value}
onChange={onChange}
/>
Expand Down

0 comments on commit e3aa838

Please sign in to comment.