Welcome, Guest
Username: Password: Remember me

TOPIC: Question re: "Making one (or more) rows of an array mandatory"

Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61235

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Hi All,

I was browsing through the Workaround section and found a way to "Making one (or more) rows of an array mandatory". I tried it and it works fine in blocking further user input when a mandatory row is empty. However when I re-enter the data into the mandatory row, the "next" button remains disable. Do I have to explicitly reactivate the "next" button? If so, how should I proceed?

Thanks,
Jack
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61237

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
FYI, this was the script I added to the array question:

<script type="text/javascript" charset="utf-8">

$(document).ready(function() {

// Interrupt the submit function
$('form#limesurvey').submit(function(){

var empty = 0;

var warningText = 'Please complete the highlighted inputs.';

// Call the mandatory row function with question IDs and row numbers
mandatoryRow(QQ, 1);
mandatoryRow(QQ, 3);

// A function to render rows of an array mandatory
function mandatoryRow(qID, rowNum) {

$( 'div#question'+qID+' table.question tbody[id^="javatbd"]:eq('+Number(rowNum - 1)+') input[type="text"]' ).each(function(i) {
if ( $( this ).val() == '' ) {
$( this ).css('background-color', 'pink');
empty = 1;
}
else {
$( this ).css('background-color', '#FFFFFF');
}
});
}

if ( empty == 1 ) {
alert (warningText);
return false;
}
else {
return true;
}
});
});
</script>
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61258

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4264
  • Thank you received: 801
  • Karma: 368
This script doesn't disable the "Next" button, it simply interrupts the next/submit function and checks for inputs in the selected array rows. Additionally, you need to replace "QQ" (lines 13 and 14) with the array question ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Interrupt the submit function
		$('form#limesurvey').submit(function(){
 
			var empty = 0;
 
			var warningText = 'Please complete the highlighted inputs.';
 
			// Call the mandatory row function with question IDs and row numbers
			mandatoryRow(QQ, 1);
			mandatoryRow(QQ, 3);
 
			// A function to render rows of an array mandatory
			function mandatoryRow(qID, rowNum) {
 
				$( 'div#question'+qID+' table.question tbody[id^="javatbd"]:eq('+Number(rowNum - 1)+') input[type="text"]' ).each(function(i) {
					if ( $( this ).val() == '' ) {
						$( this ).css('background-color', 'pink');
						empty = 1;
					}
					else {
						$( this ).css('background-color', '#FFFFFF');
					}
				});
			}
 
			if ( empty == 1 ) {
				alert (warningText);
				return false;
			}
			else {
				return true;
			}
		});
	});
 
</script>
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 4 months ago by tpartner.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61335

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Thanks Tony.

Yes I actually did enter the qID (2) as followed:
// Call the mandatory row function with question IDs and row numbers
mandatoryRow(2, 1);

For some reason all the navigation buttons (Prev, Next...etc) are disabled after I click Next with the mandatory fields left empty.
Last Edit: 3 years 4 months ago by jackywu.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61336

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
I guess both the 'Next' and the 'Submit' buttons are both considered a submit action am I correct?
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61420

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4264
  • Thank you received: 801
  • Karma: 368
For some reason all the navigation buttons (Prev, Next...etc) are disabled after I click Next with the mandatory fields left empty.
Do you have any other scripts running? Can you activatea sample survey?
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61447

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Yes, I have a Custom_On_Load to do some variable column width settings.

And I was able to activate the survey as well.

It seems like whenever I do a 'return false', the navigation buttons get disabled.
Last Edit: 3 years 4 months ago by jackywu.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61480

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4264
  • Thank you received: 801
  • Karma: 368
Oh, I see what's going on.

A "feature" to disable the navigation buttons after clicking has been added to 1.91. Unfortunately, this script destroys all workarounds that interrupt the Next/Submit function.

A quick fix until I can come up with something more elegant would be to override the "feature" by adding the following to the very end of endpage.pstpl.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('form#limesurvey').submit(function() {
			$('input[type=button], input[type=submit]', this).attr('disabled', '');
		});
 
	});
 
</script>
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 4 months ago by tpartner.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61526

  • jackywu
  • jackywu's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Thanks Tony, that worked like a charm!

I like how you put "" around the word feature haha.
The administrator has disabled public write access.

Re: Question re: "Making one (or more) rows of an array mandatory" 3 years 4 months ago #61527

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4264
  • Thank you received: 801
  • Karma: 368
Yeah, I don' think it's necessary and it has destroyed many workarounds.
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.133 seconds
Donation Image