- Posts: 107
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Scroll to first error after submit
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
More
3 years 8 months ago #204288
by Matadeleo
Scroll to first error after submit was created by Matadeleo
Hi guys, I'm trying to set up my survey so after you press "Next", if there are errors on the page then I would like to scroll to the first error. I saw a previous solution (from 7 years ago) where I had to put the below code into my theme.js
I assume this is no longer working due to the age of the solution, is there a way to do this in LS 3.5+?
Code:
$(document).ready(function() { if($('.errormandatory').length > 0) { $('html, body').animate({ scrollTop: $('.errormandatory:first').offset().top }, 2000); } });
I assume this is no longer working due to the age of the solution, is there a way to do this in LS 3.5+?
The topic has been locked.
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 107
- Thank you received: 4
3 years 8 months ago #204293
by Matadeleo
Replied by Matadeleo on topic Scroll to first error after submit
Changing the code to:
Doesn't work whilst you are in the survey, but if you close it and then come back to it, it correctly scrolls you to the first mandatory error
Code:
$(document).ready(function() { if($('.ls-question-mandatory').length > 0) { $('html, body').animate({ scrollTop: $('.ls-question-mandatory:first').offset().top }, 2000); } });
Doesn't work whilst you are in the survey, but if you close it and then come back to it, it correctly scrolls you to the first mandatory error
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
3 years 8 months ago #204317
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Scroll to first error after submit
It does work for me in version 3.22.210.
Your problem in that older version may be that you have AJAX enabled - always disable AJAX in the survey theme options. (and update to the latest 3.x version)
You may also want to add a little more offset to account for the header height.
Your problem in that older version may be that you have AJAX enabled - always disable AJAX in the survey theme options. (and update to the latest 3.x version)
You may also want to add a little more offset to account for the header height.
Code:
$(document).ready(function() { if($('.ls-question-mandatory').length > 0) { $('html, body').animate({ scrollTop: $('.ls-question-mandatory:first').offset().top - 160 }, 2000); } });
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.