Skip to content

Commit 68200c2

Browse files
authored
Merge pull request #3034 from specify/issue-3033
Forbid negative record set indexes
2 parents f4bb46a + 9a895c3 commit 68200c2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

specifyweb/frontend/js_src/lib/components/FormSliders/RecordSelectorFromIds.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ export function RecordSelectorFromIds<SCHEMA extends AnySchema>({
9191
};
9292
}, [ids, model]);
9393

94-
const [index, setIndex] = useTriggerState(defaultIndex ?? ids.length - 1);
94+
const [index, setIndex] = useTriggerState(
95+
Math.max(0, defaultIndex ?? ids.length - 1)
96+
);
9597
React.useEffect(
9698
() =>
9799
setIndex((index) =>
98-
typeof newResource === 'object'
99-
? rest.totalCount
100-
: Math.min(index, rest.totalCount - 1)
100+
Math.max(
101+
0,
102+
typeof newResource === 'object'
103+
? rest.totalCount
104+
: Math.min(index, rest.totalCount - 1)
105+
)
101106
),
102107
[newResource, rest.totalCount]
103108
);

0 commit comments

Comments
 (0)