Check out the LimeSurvey source code on GitHub!

Quick question about double alert messages

More
5 years 6 months ago #64646 by doodsonj_duplicate
Hi Team,

I don't think that this is the right place to ask this question so feel free to delete the question.

Can you point me in the right direction as to why the alert in the following question is repeating twice? The code initiates when a previous/next button is clicked, and the alert is correctly only shown when the 'Next' button is clicked. However, the alert repeats twice. Any ideas or pointing me into the right direction would be brilliant.
$(document).ready(function() {
	$('form#limesurvey').submit(function(){	
 
 
		if (document.limesurvey.move.value == 'moveprev') {
		}
 
		else {
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
			alert("FORWARD");
 
		};
 
	});
 
});

Please Log in to join the conversation.

More
5 years 6 months ago #64669 by tpartner
What version are you using? There was a bug causing the submit function to fire twice but I believe it was fixed - bugs.limesurvey.org/view.php?id=4985

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 6 months ago #64672 by paulfiner
I too am seeing double alert messages. I'm using the latest build.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 6 months ago #64673 by doodsonj_duplicate
I couldn't find the build number but the bottom of the screen reads as v1.91+ which I think is later than Bugfix in the report.

Any ideas how to get around the problem?

Please Log in to join the conversation.

More
5 years 6 months ago #64674 by tpartner
Can one of you please activate a sample survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 6 months ago #64676 by doodsonj_duplicate
Hi both :)

The bug isn't replicated using the sample survey in the bug report that you linked. Also, by constant breakpoints and commenting out, I've managed to locate what seems to be causing the problem but I have no idea why it would be causing such an issue.

In the same script, I am using the 'Multiple questions types' workaround from here: docs.limesurvey.org/tiki-index.php?page=...stion_types_in_array

The double messages only appear when the line is run:
    $('.'+this+'').wrapAll('<div id="inlineWrapper'+i+'" class="inlineRow" />');

The line in context is:
//Wrap each "row" in a wrapper div
$(rowList).each(function(i) {
    $('.'+this+'').wrapAll('<div id="inlineWrapper'+i+'" class="inlineRow" />');
}); 

I have commented out the line, and the script runs perfectly (though the layout from the workaround does not work).

I have also commented out later reference to inlineWrapper and inlineRow but these have no impact at all. Consequently, I think it is something to do with wrapAll (I've also checked and 'this' doesn't ever seem to call the submit button)

Any ideas?

J.

Please Log in to join the conversation.

More
5 years 6 months ago #64679 by tpartner
Not really. In that line, 'this' simply references an array item that is being inserted as a class for the selector. All elements that match the selector are then wrapped in a new <div> element. So the loop is actually:
$('qRow0 ').wrapAll('<div id="inlineWrapper0" class="inlineRow" />');
$('qRow1 ').wrapAll('<div id="inlineWrapper1" class="inlineRow" />');
$('qRow2 ').wrapAll('<div id="inlineWrapper2" class="inlineRow" />');
$('qRow3 ').wrapAll('<div id="inlineWrapper3" class="inlineRow" />');
...

And I still haven't been able to reproduce it. Is it browser-specific?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 6 months ago #64680 by doodsonj_duplicate
Yep, I put breakpoints in to see the value of 'this' before, and it produced something similar to the output you provided.

I have reproduced the error in Chrome, IE, Safari and Firefox (all latest versions).

I can't work out why commenting out that line solves the problem.

The error still occurs even when I choose different names for 'inlineWrapper/Row' (just in case it was an issue of the script halting because other lines relied on that line being present).

Hmm.

Please Log in to join the conversation.

More
5 years 6 months ago #64682 by tpartner
Can you activate a small sample survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 6 months ago #64695 by doodsonj_duplicate
Hi Tony,

Sure, if you don't mind having a look.

phd-research.limequery.com/38368/lang-en

Thanks, J.

Please Log in to join the conversation.

More
5 years 6 months ago #64698 by tpartner
Okay, I don't get what is firing the submit function twice. Can you attach the survey here (or send me a PM if it's sensitive) so I can test it directly?

Paul, are you only seeing the problem when using the 'Multiple questions types' workaround?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: doodsonj_duplicate

Please Log in to join the conversation.

More
5 years 6 months ago #64700 by paulfiner
Hi Tony

Just doing a quick test, it looks like it is only happening on the Multiple questions workaround.
Putting up an alert on a normal question on the next page only gave one alert.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #64718 by doodsonj_duplicate

File Attachment:

File Name: limesurvey...p_45.lsg
File Size:150 KB

Hi Tony,

Thanks for offering, though don't worry if you don't have time or more important/exciting things to do.

I have attached the script.

To make the script work, you'll likely to have change the variable qHiddenTextIDNum1 to the qID of GroupsGroupsHidden (a long-text field at the end of the list).

Sorry about the state of the code, I'm still writing the code and haven't had chance to make it all super clean and pretty yet.

Peter - feel free to use any part of the (rather ugly at the moment) script as the script combines the ability to multiples types of question in an array, add/remove rows, validation colouring (i.e. highlighting rows). This script is probably the simplest that I have but I've got a few others that I've written which have added a few other features (or used existing code from the workarounds).

File Attachment:

File Name: limesurvey...p_45.lsg
File Size:150 KB



J.
Attachments:
Last Edit: 5 years 6 months ago by doodsonj_duplicate. Reason: Wrong file
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #64735 by tpartner
Okay, got it!

jQuery is getting getting confused when wrapping an element that contains a script. It seems to leave a ghost image of the script so there are effectively two scripts and therefor two $('form#limesurvey').submit() calls.

I see 2 solutions, the first being the easiest to implement and the second making future development far easier (you don't have to mess with the editor):

1) Move the script to the source of the group description.

2) Move the script to template.js and wrap most of it in an IF statement so it only fires when on that page. Something like this:
var qHiddenTextIDNum1 = 1196;
 
if($('#question'+qHiddenTextIDNum1+'').length > 0) {
 
	var myGlobalRows = 10;
	var myGlobalColumns = 3;
	var RowCutOffFreetext = 6;		       
	var RowCutOffHide = 6;
	var RowCutOffHideOriginal = RowCutOffHide;
	var myArrayTableTracker = new Array(myGlobalRows); 
 
	//// And the code continues here....
 
}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 6 months ago by tpartner.
The following user(s) said Thank You: doodsonj_duplicate

Please Log in to join the conversation.

More
5 years 6 months ago #64740 by doodsonj_duplicate
Perfect. That has solved everything :) HURRAH, Tony.

I think it is about time that I donate some money to the cause, so I'll get onto that in the next 12 hours :)

As ever, thank you so much for helping me out with my problem.

Peter - if you're implementation is similar to mine, then this solves the problem.

J.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form