Array(texts) - Validate only 1 column

More
3 years 4 months ago - 3 years 4 months ago #163387 by jackuars
So am trying to validate only a single column of an ArrayTexts question. Is there any way to do it? For instance Years of Experience column should contain only numbers

Last edit: 3 years 4 months ago by jackuars.

Please Log in to join the conversation.

More
3 years 4 months ago #163394 by jelo
Take a look at the section here:
manual.limesurvey.org/Expression_Manager....27that.27_variables

Attached is an old, modified example from this forum.
Should do the trick.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Attachments:

Please Log in to join the conversation.

More
3 years 4 months ago - 3 years 4 months ago #163399 by jackuars
Thanks for this.

On second thought, I wondered instead of "Years of Experience" I would like to have 2 subquestions From (year) & To (year) which will work as a DatePicker question.

So it should appear like this

Name of the Organization | From (Date) | To(Date) | Designation

This would mean that we've this ArrayText question will have a text box and datepicker too. Is it possible to set-up like this?
Last edit: 3 years 4 months ago by jackuars.

Please Log in to join the conversation.

More
3 years 4 months ago - 3 years 4 months ago #163404 by jelo
LimeSurvey is not supporting free from questions (mixing questions) out of the box via GUI.

LS 3.X might be a gamechanger cause the templatesystem will allow to create questionsthemes.
manual.limesurvey.org/New_Template_System_in_LS3.x
There are some workarounds for older LS version which mix different questions in a arrayquestion.
But I have never seen a workaround with a date/time picker in an arrayquestion.

Multiple question types in array
manual.limesurvey.org/Workarounds:_Quest...stion_types_in_array

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Last edit: 3 years 4 months ago by jelo.

Please Log in to join the conversation.

More
3 years 4 months ago #164051 by jackuars
Can it be done using javascript? I hope tpartner reads this thread

Please Log in to join the conversation.

More
3 years 4 months ago - 3 years 4 months ago #164057 by Joffm
Hi,

yes there is an example. Not exactly your desire, but a start and the important thing, the range.
Instaed of months just insert years.

Do a search for Tony's posts about arrays



Here is the script:
<script type="text/javascript" charset="utf-8">		
 
	$(document).ready(function(){	
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Assign column-specific classes
		$('table.subquestion-list tr', thisQuestion).each(function(i) { 
			$('> *:gt(0)', this).each(function(i){
				$(this).addClass('column-'+(i+1));
				$(this).attr('data-column', i+1);
			});
		});
 
		// Hide the text inputs in columns 2
		$('.column-2 input[type="text"]', thisQuestion).hide();
 
		// Define the select element (dropdown)
		var select1 = '<select class="inserted-select"> \
							<option value="">-- Bitte, wählen --</option> \
							<option value="Europa">Europa</option> \
							<option value="Afrika">Afrika</option> \
							<option value="Asien">Asien</option> \
							<option value="Amerika">Amerika</option> \
							<option value="Australien">Australien</option> \
						</select>';
 
		// Insert the select elements into column 2
		$('.answer-item.column-2').append(select1);
 
		// Initial dropdown values in column 2 (if the question has already been answered)
		$('.answer-item.column-2 input[type="text"]').each(function(i){
			if($.trim($(this).val()) != '') {
				$(this).closest('td').find('.inserted-select').val($.trim($(this).val()));
			}
		});
 
		// Listener on the dropdowns (insert selected values into hidden text input)
		$('.inserted-select').change(function() {
			var thisInput = $(this).closest('td').find('input[type="text"]');
			$(thisInput).val($(this).val());
			checkconditions($(thisInput).val(), $(thisInput).attr('name'), 'text');
		});
 
 
		// Insert the sliders
		$('.answer-item.column-3 input[type="text"]', thisQuestion).each(function(i) {
			$(this).closest('td').addClass('with-slider');
			var thisValue = $(this).val();
			var thisValueArr = thisValue.split(',');
			var sliderValues = [];
			if(thisValueArr.length > 1) {
				$(thisValueArr).each(function(i) {
					sliderValues.push(Number(this));
				}); 
			}
			else {
				sliderValues = [1, 12];
			}
 
			$(this).bootstrapSlider({
				'min': 1,
				'max': 12,
				'step': 1,
				'range': true,
				'value': sliderValues,
				'tooltip': 'always'
			});
 
			// Initialization stuff
			if(thisValue == '') {
				$(this).val('');
				$(this).closest('td').find('.tooltip').hide();
			}
			else {
				updateCallOut($(this).closest('td'));
			}
		});
 
		// A function to insert months in the slider callout
		function updateCallOut(el) {
			var thisTooltip = $(el).find('.tooltip');
			var thisValueArr = $(el).find('input[type="text"]').val().split(',');
			var months = {
				1: 'Januar', 
				2: 'Februar', 
				3: 'März', 
				4: 'April', 
				5: 'Mai', 
				6: 'Juni', 
				7: 'Juli', 
				8: 'August', 
				9: 'September', 
				10: 'Oktober', 
				11: 'November', 
				12: 'Dezember'
			};
			var startMonth = months[thisValueArr[0]];
			var endMonth = months[thisValueArr[1]];
			var callOutText = startMonth;
			if(startMonth != endMonth) {
				callOutText = startMonth+'-'+endMonth;
			}
			$('.tooltip-inner', thisTooltip).text(callOutText);
			thisTooltip.show().css('margin-left', '-'+(thisTooltip.width()/2)+'px');
		}
 
		// Listener on sliders
		$('td.with-slider .slider').on('mousedown', function(event, ui) {
			updateCallOut($(this).closest('td'));
		});			
		$('td.with-slider input[type="text"]', thisQuestion).on('slide slideStop', function(event, ui) {
			updateCallOut($(this).closest('td'));
			checkconditions($(this).val(), $(this).attr('name'), 'text');
		});
 
		// Listener on resizing (override the bootstrap callout behaviour)
		$(window).resize(function() {
			$('td.with-slider', thisQuestion).each(function(i) {
				if($('input[type="text"]', this).val() != '') {
					updateCallOut(this);
				}
			});
		});
 
		// Some clean-up styles (could be placed in template.css
		$('select', thisQuestion).css({
			'border': '2px solid #dce4ec',
			'padding': '0.7em',
			'border-radius': '4px'
		});
		$('.slider.slider-horizontal', thisQuestion).css({
			'margin': '1.7em auto 1em'
		});
		$('.slider-handle', thisQuestion).css({
			'top': '-4px'
		});
	});
</script>

Regards
Joffm

Slightly adapted:



Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 3 years 4 months ago by Joffm.

Please Log in to join the conversation.

More
3 years 4 months ago #164068 by Joffm
Or do it the easy way:


with question validation:
(is_numeric(self.sq_SQ001_X003)) and (self.sq_SQ001_X003>1990) and
(is_numeric(self.sq_SQ001_X004)) and (self.sq_SQ001_X004<2019)
and... (for all subquestions)

X003 and X004 the third and fourth column.

Regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in to join the conversation.

More
3 years 4 months ago #164090 by tpartner
I think the example Joffm supplied with the sliders is the most elegant. It requires little or no validation.

In the second example, you would also want to check that the "From" is always before the "To". This would also be the case if we inserted date pickers in those columns.

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
2 years 4 months ago #180251 by lemmon
Unfortunately this example does not work with 3.x, as is the case with most of the code which can be found in this forum for working with text arrays. This makes it really difficult for people who are starting off with a current version of LS. It would be great to have a topic specifically for 3.x users with examples of. I will start one once I have something working.

Please Log in to join the conversation.

More
1 year 2 weeks ago #200574 by JaimeAvalos
I have an array of texts with 15 lines and I have to apply a range validation. Is there a way to set conditions like those but using the self.sq_ notation to do all in one shot?

I tried:

((self.sq_3) <= 50) and (self.sq_3) >= 1)) or (is_empty(sq_3))

but it does not work.

Please Log in to join the conversation.

More
1 year 2 weeks ago #200612 by Joffm
Hi,
even if you correct your errors with your brackets
((self.sq_3) <= 50) and (self.sq_3) >= 1)) or (is_empty(sq_3))

((self.sq_X3<=50) and (self.sq_X3>=1)) or is_empty(self.sq_X3)

I used X3 to avoid a conflict with "SQ003".


((self.sq_X3<=50) and (self.sq_X3>=1)) is expanded to:
((Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3 <= 50) and (Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3 >= 1)

and
is_empty(self.sq_X3).is expanded to :
is_empty(Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3, Q1_SQ004_X3)


Obviously this cannot be validated.



Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 month 3 weeks ago #215546 by fmdallafontana
Hi,

I'm having some problems using the <, <=, >, >= operators. Subquestion equation doesn't work for these cases, but it works for the ==.
I'm using version 2.72.3+171020. How can I solve it?

Regards,
Fernando

Please Log in to join the conversation.

More
1 month 3 weeks ago #215549 by holch
This should work for < and > as well. Can you provide an example of your problem as LSS file (copy your survey, delete everything that is irrelevant to the problem and export it as LSS).

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
1 month 2 weeks ago #215585 by fmdallafontana

This should work for < and > as well. Can you provide an example of your problem as LSS file (copy your survey, delete everything that is irrelevant to the problem and export it as LSS).

Sadly it doesn't work in my case.
I was doing some tests, and it turns out that the equation identifies the "written" form of these operators. I mean:
"gt" for ">"
"ge" for ">="
"lt" for "<",
and "le" for "<=".

Don't ask me how I came to try these alternatives =)

Please Log in to join the conversation.

More
1 month 2 weeks ago #215587 by Joffm
Well, the "<", ">" ,and so on are accepted, but you have to take care that the editor doesn't identifies them as the start or end of an HTML tag.
And as you didn't show us your question with this subquestion relevance equation, it was difficult to say anything.

But the "verbatim" form is always better.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now