Prevent error when press next or previous buttons