Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Question type - Date

Question type - Date 3 years 9 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 3 years 9 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.

Re: Aw: Question type - Date 3 years 9 months ago #56391

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6551
  • Thank you received: 868
  • Karma: 257
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).

:)
The administrator has disabled public write access.

Aw: Re: Aw: Question type - Date 3 years 9 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.

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

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
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.

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

Aw: Re: Aw: Re: Aw: Question type - Date 3 years 9 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.

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

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
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.

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

Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 3 years 9 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.

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

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
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.

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: Aw: Re: Aw: Re: Aw: Re: Aw: Question type - Date 3 years 9 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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.249 seconds
Donation Image