Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Prevent accidentially closing the survey

Prevent accidentially closing the survey 2 years 7 months ago #107916

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
I edited your post in the wiki...

Thanks and see you!
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 7 months ago #107917

  • DenisChenu
  • DenisChenu's Avatar
  • Online
  • Moderator Lime
  • Posts: 9580
  • Thank you received: 1374
  • Karma: 390
And maybe it's best to use something like this:
if(!$('#submitted').length || $('.button,[name='move']').length)

Think it's best (have to test ...)
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 7 months ago #107997

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
DenisChenu wrote:
$('.button,[name='move']').length

Yes, that's probably better than finding it out based on the <div>. I'm not sure if that then covers all cases...
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 4 months ago #111049

  • LS_SR
  • LS_SR's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Thank you received: 2
  • Karma: 0
Where can I change the alert text and the alert-button text?

I tryed the program Poedit, but that's not working.
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 4 months ago #111050

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Hi LS_SR,

you can adapt the German sentences in the code (at e.returnValue and return) BUT for Firefox and similar browsers, the text is built-in and you cannot change it. You would need to rewrite the function for Firefox. Also, you cannot change the text of the button of javascript's alert() function, so you would have to use a differnet solution to implement an alert with a custom button, like using jQuery's alert functions...

Best
jonsen
The administrator has disabled public write access.
The following user(s) said Thank You: LS_SR

Prevent accidentially closing the survey 2 years 4 months ago #111051

  • LS_SR
  • LS_SR's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Thank you received: 2
  • Karma: 0
Thanks for your fast answer.
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 10 months ago #116036

  • fanepic
  • fanepic's Avatar
  • Offline
  • Junior Lime
  • Posts: 21
  • Karma: 0
Thanks a lot for your Code.
Do you now how it's possible to make en exception for the languagechanger?

Cheers
Benny
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 10 months ago #116038

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Hi fanepic,

please try to add ".changelang" to the jQuery "on" action by changing this:
$(document).on('click',".button,[name='move']", ...

to this:
$(document).on('click',".button,.changelang,[name='move']", ...

Please leave a quick comment if this works, otherwise I'll have a closer look.

Best
jonsen
The administrator has disabled public write access.
The following user(s) said Thank You: fanepic

Prevent accidentially closing the survey 1 year 10 months ago #116039

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 10 months ago #116042

  • fanepic
  • fanepic's Avatar
  • Offline
  • Junior Lime
  • Posts: 21
  • Karma: 0
Thank you jonson works fine.

Do you also now how to make it Multilanguage like only show if it's German?

Regards
fanepic
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 10 months ago #116085

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
You can try using the {LANG} placeholder and maybe put everything into an IF statement like
...
if({LANG}=='de')
{
...
}

{LANG} should get replaced by Limesurvey with the current survey language.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 8 months ago #118624

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Hi everyone,

the code has been working well on all of my past surveys. BUT now I have a survey which contains a file uploader question and there IT DOESN'T WORK CORRECTLY!

How to replicate the problem:
1. Add the code ( manual.limesurvey.org/Workarounds:_Surve...y_closing_the_survey ) to your template.js
2. Add a file uploader question
3. Navigate through the survey. If you open the file uploader, you will be asked if you want to leave the page EVEN THOUGH you use the LS navigation (the "next" or "previous" buttons).
4. Notice that you will not have the this problem if you just pass through that question without opening the uploader iframe.

The function works based on a <input type="hidden" id="submitted" /> tag being added when using the navigation, which then again is being checked for by the "goodbye" function to see if the buttons were used. The interesting point: Even though this tag is appeded to the end of the <body> correctly when using the navigation (even after opening the file uploader), the goodbye function does not recognize it. How can this be? It works flawlessly for all other pages, why not here? Does it have something to do with the iframe (which is the only differnce to other pages that I can see)?

I'm really looking forward to a new perspective on this, as I have been stuck on this for a week now. Thank you very much!

Best
Jonsen
Last Edit: 1 year 8 months ago by jonsen.
The administrator has disabled public write access.

Prevent accidentially closing the survey 1 year 8 months ago #118659

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
Yeah, I think the problem is that, with the introduction of a second <body> element in the iframe, the scope to look for the "#submitted" element gets messed up.

Additionally, I'm not keen on introducing unnecessary input elements - I think it's better handled by adding a class to the <body> element.

So, try this which uses a class instead of a hidden input to indicate a valid move and limits the scope for the <body> elements to the top window (ignoring anything in an iframe).

function goodbye(e) {
	if(!$('body', top.document).hasClass('submitted')) { //check if a button was used to navigate or the survey is completed
		if(!e) e = window.event;
		//e.cancelBubble is supported by IE - this will kill the bubbling process.
		e.cancelBubble = true;
		e.returnValue = 'Are you sure you want to quit this survey?'; //This is displayed on the dialog for IE
 
		//e.stopPropagation works in Firefox.
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();
		}
 
		return 'Are you sure you want to quit this survey?'; // For chrome
	}
 
}
 
window.onbeforeunload = goodbye;
 
$(document).on('click', '.button, .changelang, [name="move"]', function(event){ //added .changelang here, please add other classes if you know which should be allowed to navigate
	$('body', top.document).addClass('submitted');
});
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
The following user(s) said Thank You: jonsen

Prevent accidentially closing the survey 1 year 8 months ago #118701

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Thank you, Tony! I re-added !$('#completed').length for the final page, so one can leave the finished survey without being asked and also tried to fix it for the template editor by looking for the '.templateeditor' class...

Hope this does it for now! I updated the workaround in the wiki...
//FEATURES: (2015-03-27) Now with fix for iframes (e.g. file uploader) and the template editor 
function goodbye(e) {
    if(!$('body', top.document).hasClass('submitted') && !$('#completed').length && !$('.templateeditor', top.document).length) { //check if a button was used to navigate OR the survey is completed OR the template is displayed in the template editor
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.346 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form