Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Question type - Date

Question type - Date 5 years 5 months ago #56365

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Is it possible to change the dropdown representation of the date question type to show only the month and the year dropdown boxes?

I don't need a specific date, since I will be asking for an event back in the past. So the month and the year would be enough, to avoid missing values because of poor memory.

Kind regards
Danny
The administrator has disabled public write access.

Aw: Question type - Date 5 years 5 months ago #56387

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
I found the code for the dropdown date menu in quanda.php. Can I simple hide the code for "Show day select box"?
if (trim($qidattributes['dropdown_dates'])!=0) {
        if (!empty($_SESSION[$ia[1]]))
        {
            list($currentyear, $currentmonth, $currentdate) = explode('-', $_SESSION[$ia[1]]);
        } else {
            $currentdate='';
            $currentmonth='';
            $currentyear='';
        }
 
        $dateorder = preg_split('/[-\.\/ ]/', $dateformatdetails['phpdate']);
        $answer='<p class="question">';
        foreach($dateorder as $datepart)
        {
            switch($datepart)
            {
                // Show day select box
                case 'j':
                case 'd':   $answer .= ' <select id="day'.$ia[1].'" class="day">
                                                <option value="">'.$clang->gT('Day')."</option>\n";
                for ($i=1; $i<=31; $i++) {
                    if ($i == $currentdate)
                    {
                        $i_date_selected = SELECTED;
                    }
                    else
                    {
                        $i_date_selected = '';
                    }
                    $answer .= '    <option value="'.sprintf('%02d', $i).'"'.$i_date_selected.'>'.sprintf('%02d', $i)."</option>\n";
                }
                $answer .='</select>';
                break;
                // Show month select box
                case 'n':
                case 'm':   $answer .= ' <select id="month'.$ia[1].'" class="month">
                                            <option value="">'.$clang->gT('Month')."</option>\n";
                $montharray=array(
                $clang->gT('Jan'),
                $clang->gT('Feb'),
                $clang->gT('Mar'),
                $clang->gT('Apr'),
                $clang->gT('May'),
                $clang->gT('Jun'),
                $clang->gT('Jul'),
                $clang->gT('Aug'),
                $clang->gT('Sep'),
                $clang->gT('Oct'),
                $clang->gT('Nov'),
                $clang->gT('Dec'));
                for ($i=1; $i<=12; $i++) {
                    if ($i == $currentmonth)
                    {
                        $i_date_selected = SELECTED;
                    }
                    else
                    {
                        $i_date_selected = '';
                    }
 
                    $answer .= '    <option value="'.sprintf('%02d', $i).'"'.$i_date_selected.'>'.$montharray[$i-1].'</option>';
                }
                $answer .= '    </select>';
                break;
                // Show year select box
                case 'Y':   $answer .= ' <select id="year'.$ia[1].'" class="year">
                                            <option value="">'.$clang->gT('Year').'</option>';
 
                /*
                 *  New question attributes used only if question attribute
                 * "dropdown_dates" is used (see IF(...) above).
                 *
                 * yearmin = Minimum year value for dropdown list, if not set default is 1900
                 * yearmax = Maximum year value for dropdown list, if not set default is 2020
                 */
                if (trim($qidattributes['dropdown_dates_year_min'])!='')
                {
                    $yearmin = $qidattributes['dropdown_dates_year_min'];
                }
                else
                {
                    $yearmin = 1900;
                }
 
                if (trim($qidattributes['dropdown_dates_year_max'])!='')
                {
                    $yearmax = $qidattributes['dropdown_dates_year_max'];
                }
                else
                {
                    $yearmax = 2020;
                }
 
                if ($yearmin > $yearmax)
                {
                    $yearmin = 1900;
                    $yearmax = 2020;
                }
 
                if ($qidattributes['reverse']==1)
                {
                    $tmp = $yearmin;
                    $yearmin = $yearmax;
                    $yearmax = $tmp;
                    $step = 1;
                    $reverse = true;
                }
                else
                {
                    $step = -1;
                    $reverse = false;
                }
 
                for ($i=$yearmax; ($reverse? $i<=$yearmin: $i>=$yearmin); $i+=$step) {
                    if ($i == $currentyear)
                    {
                        $i_date_selected = SELECTED;
                    }
                    else
                    {
                        $i_date_selected = '';
                    }
                    $answer .= '  <option value="'.$i.'"'.$i_date_selected.'>'.$i.'</option>';
                }
                $answer .= '</select>';
 
                break;
            }
        }
The administrator has disabled public write access.

Aw: Question type - Date 5 years 5 months ago #56391

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
Yes ,

You can modify the limesurvey code, but i think there is another solution in javascript.

Try something like that with QQQ your question number. ( in the question text).
$(document).ready(function(){
  $('#questionQQQ select.day option[value='1']').attr("selected", "selected");
  $('#questionQQQ select.day').hide();  
})

First try without the hide, to control day 1 are selected. (if not date cannot be integrated to database).

:)
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Aw: Re: Aw: Question type - Date 5 years 5 months ago #56420

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Ok, so I tried to add the following javascript code, in the question text field. My question id is 426. Unfortunately it didn't work, the day dropdown-box is still visible.
<script type="text/javascript">
$(document).ready(function(){
  $('#question426 select.day option[value='1']').attr("selected", "selected");
  $('#question426 select.day').hide();  
})
</script>
Any other suggestion, what I have done wrong?

If it is not working with javascript, would it be possible to change the code in quanda.php? I will have only one survey running, where I need the date question format. After the end of that survey I could change it back. But I am not sure what I have to change, so the date is saved correctly in the database. Any help is greatly appreciated.
The administrator has disabled public write access.

Aw: Re: Aw: Question type - Date 5 years 5 months ago #56429

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
I think there's a couple of small typos. Try:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
		$('#question426 select.day option[value="01"]').attr("selected", "selected");
		$('#question426 select.day').hide();  
	})
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56457

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Now its working in the preview of that single question (id 426). But when I try the preview of the group of questions or the whole survey, all three dropdown boxes are visible again.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56461

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
Is the day first day of the month being selected? Are there any Javascript errors in the error console?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56475

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
When I run the preview of the single question, everything looks fine and the day filed is hided. When I run the group or survey preview, all three boxes are visible and also the first day of the month is not selected.

I the firefox error console I found a few warnings and the following error:

Fehler: autoArray.list is undefined
Quelldatei: ima-research.eu/survey/scripts/survey_runtime.js
Zeile: 68


Kind regards
Danny
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56479

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
I think that something in your template may be causing the JS to fail. Test it with the default template.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56500

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Same problems with the default template.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56503

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
I can't explain that. I have tested in IE and Firefox and it works fine.

Can you put a simple alert in to see if the script is running?
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
		$('#question426 select.day option[value="01"]').attr("selected", "selected");
		$('#question426 select.day').hide();
		alert ('Script runs!');  
	})
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56506

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Same issue. The script is running in the single question preview but not in the whole survey preview.

Is it possible to send you my login informations, so you can have a look by yourself?

By the way, I have tested in Safari and Firefox.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56507

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
Sure, send me a PM.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
The following user(s) said Thank You: DPajak

Aw: Re: Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 5 years 5 months ago #56523

  • DPajak
  • DPajak's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thanks to Tony the problem is solved.

There was a JavaScript bug (see bugs.limesurvey.org/view.php?id=4938). It will be fixed in a future release.

In the meantime one can apply the fix in the installation - in /scripts/survey_runtime.js.

Change line 68 from :
if ((autoArray.list.length > 0)){

to:
if (autoArray.list != "undefined"){
Last Edit: 5 years 5 months ago by DPajak.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.245 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form