Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Datepicker in Multiple Short Text question

  • ggcsoarbc
  • ggcsoarbc's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132790 by ggcsoarbc
I'm sure this is possible, but I need direction from someone more experience than myself. I found and applied the solution to get a datepicker to pop up in one column of an array style question, but now I want to add a datepicker to just one row of a multiple short text question and I can't figure out how to make it work! Can someone help me?

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132795 by tpartner
Replied by tpartner on topic Datepicker in Multiple Short Text question
LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ggcsoarbc
  • ggcsoarbc's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132796 by ggcsoarbc
Replied by ggcsoarbc on topic Datepicker in Multiple Short Text question
Version 2.06+ Build 151215
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132797 by tpartner
Replied by tpartner on topic Datepicker in Multiple Short Text question
This should work. Adjust the "timeRow " variable as necessary. (this example inserts the timepicker in row 2)

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {  
 
    // Identify some elements
    var thisQuestion = $('#question{QID}');
 
    var surveyRoot = location.pathname.split('index.php')[0];
 
    // Row to insert the timepicker
    var timeRow = 2;
 
    // Define the timepicker
    function insertPicker() {
      $('li.question-item:eq('+(timeRow-1)+') input[type="text"]', thisQuestion).datetimepicker( {
        minInterval: (1000*60*60), // 1hr
        dateFormat: 'dd M yy', 
        timeFormat: 'HH:mm',
        start: { }, // start picker options
        end: { } // end picker options          
      });
    }
 
    // Insert the timepicker
    if (!$.isFunction($.fn.timepicker)) {      
      $('head link[rel="stylesheet"]').last().after('<link rel="stylesheet" href="'+surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.css" type="text/css" media="screen">');
      $.getScript( surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.js', function( data, textStatus, jqxhr ) {
        insertPicker();
      });
    }
    else {  
      insertPicker();
    }
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...4(1).lss
File Size:15 KB

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: Stan, ggcsoarbc
The topic has been locked.
  • ggcsoarbc
  • ggcsoarbc's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132798 by ggcsoarbc
Replied by ggcsoarbc on topic Datepicker in Multiple Short Text question
First - thank you for your prompt response.

When I import your sample survey, that works, but when I copy and paste into my question, at first it didn't work. I played around with it and learned that if I have a "Display rows" under advanced settings set to 1 (which is what I had, so that the other boxes can be made larger, if necessary), then the picker does not work. When I removed the 1 and left that setting blank, then the picker works.

I don't actually want a time in this field - just a date - how do I make it for a date only? (format yy/mm/dd).

And, is it possible to allow one of the rows to have more than one row showing, without messing up the datepicker ability?
The topic has been locked.
  • ggcsoarbc
  • ggcsoarbc's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago - 8 years 1 month ago #132799 by ggcsoarbc
Replied by ggcsoarbc on topic Datepicker in Multiple Short Text question
I've got it to work without the time.

Thank you for your help. But now that I can't put in the number of rows showing without breaking the date picker, how can I make it so that one of the rows (in particular, it is the 3rd row) shows more rows available for text input?

Thanks again.
Last edit: 8 years 1 month ago by ggcsoarbc.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132800 by tpartner
Replied by tpartner on topic Datepicker in Multiple Short Text question

how can I make it so that one of the rows (in particular, it is the 3rd row) shows more rows available for text input?

You cannot do that - the rows are either all text inputs (single-row) or textareas (multi-row);

As far as I know, the datepicker only works on text input elements.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago - 8 years 1 month ago #132813 by DenisChenu
Replied by DenisChenu on topic Datepicker in Multiple Short Text question
Hi,

Not directly linked with the question, just some js survey hacker :
Code:
var surveyRoot = location.pathname.split('index.php')[0];

I like to use
Code:
var surveyRoot = "{TEMPLATEURL}../../../
But can break with included template
But now, you can use
Code:
var surveyRoot = "{SURVEYRESOURCESURL}../../../

:)
PS: then index.php system can be broken with some specific parameters url

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 1 month ago by DenisChenu. Reason: remove a /
The topic has been locked.
More
8 years 1 month ago #133372 by Stan
Thanks Tpartner for this.
A question, how can i successfully adjust the code, so that it would be possible to:
- Display only the month and the year ('MM yy')?
- set the minDate and the maxDate?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #133404 by tpartner
Replied by tpartner on topic Datepicker in Multiple Short Text question
You can do that with the normal jQuery UI Datepicker , using the dateFormat, minDate and maxDate options. Something like this:

Code:
Q1:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {  
 
    // Identify some elements
    var thisQuestion = $('#question{QID}');
 
    // Row to insert the timepicker
    var timeRow = 2;
 
    // Insert the timepicker
    $('li.question-item:eq('+(timeRow-1)+') input[type="text"]', thisQuestion).datepicker({
      dateFormat: 'mm-yy', 
      minDate: new Date("February 01, 2016"), 
      maxDate :new Date("May 31, 2016")  
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2759.lss
File Size:15 KB

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: Stan
The topic has been locked.
More
8 years 1 month ago #133467 by Stan
Thanks a lot Tpartner,

i actually tried to play with the jQuery UI but it wasn't so easy :P
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose