Welcome, Guest
Username: Password: Remember me

TOPIC: I need to add datepickers to fields within a subquestion.

I need to add datepickers to fields within a subquestion. 2 years 10 months ago #69903

I have searched the forums in an effort to find some javascript code that would allow me to modify a subquestion field so that it displays a data picker on entry. Is such a thing possible?

Thanks
The administrator has disabled public write access.

Re: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #69914

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
What question types are you using? If a multiple text type, do you want the pickers on all inputs?
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: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #69915

tpartner, thanks for the quick reply. First, let me say that you guys have been awesome! The question type is an array text question. There are four columns and two rows in the array. I need date pickers for the fields in the first two columns only (two columns, two rows).

Thanks in advance for your help.

Also, one other question: When using tokens, is it possible to create a pool of custom attributes that are shared by all token holders or does each token have to assigned its own set of custom attributes?

Thanks again.
The administrator has disabled public write access.

Re: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #69919

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
You can assign column-specific classes to the array cells and then use those to apply the datepicker to the text inputs.

1) Set up your survey to use JavaScript.

2) Create your array question.

3) Add the following script to the source of the array. Replace "QQ" with the array question ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
 
		// Add column-specific classes to array cells
		$('#question'+qID+' table.question tr').each(function(i, el){
			$('> *', this).each(function(i, el){
				$(el).addClass('col-'+i);
			});
		});
 
		// Apply datepicker to text inputs
		$('#question'+qID+' .col-1 input[type="text"], #question'+qID+' .col-2 input[type="text"]').datepicker({
			dateFormat: 'dd/mm/yy'
		});
 
	});
 
</script>

There is more info on the datepicker options here - jqueryui.com/demos/datepicker/

As for the tokens - the attributes must be set for every token but you may be able to use JavaScript to set "global" variables to use for all respondents. (maybe food for a new thread)
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: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #69921

Thanks. I will give this a try and follow-up with the results. Per the token attributes, if the javascript solution is possible, I think it would be an excellent workaround to add to the token workarounds list. The goal is to enable the survey provider to use tokens to enable unique attributes to populate survey fields for respondents that are registering to take the survey as well as those that were directly invited.
The administrator has disabled public write access.

Re: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #70035

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
Please open a new thread for the token problem because it's a completely different issue.

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

Re: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #70056

The datepicker works perfectly. Thanks so much for your help. I'll get a donation out to you.
The administrator has disabled public write access.

Re: I need to add datepickers to fields within a subquestion. 2 years 10 months ago #70068

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
Sounds great, thanks!

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.124 seconds
Donation Image