- Posts: 6
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Load the timepicker JS and CSS var surveyRoot = location.pathname.split('index.php')[0]; $('<link rel="stylesheet" type="text/css" href="'+surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.css" >').appendTo('head'); $.getScript(surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.js', function() { // Okay, JS is loaded...initialize the timepicker $('input[type="text"]', thisQuestion).timepicker({ timeFormat: "HH:mm", hourMin: 2, showTime: true, onClose: function() { $('button.ui-datepicker-current').show(); } }); }); // Hide the "Now" button and reposition the timepicker $('input[type="text"]', thisQuestion).on('click focus', function() { $('button.ui-datepicker-current').hide(); $("#ui-datepicker-div").position({ my: "left top", at: "left-3 top-3", of: $(this) }); }); }); </script>
Do not change that.The only thing I changed is the QID in the right question number
Sorry, I missed that requirement - it will require a listener on Q2 which I don't have time for today.Because in that question patients have to fill in a time which is higher than the previous filled in time.
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the questions var timeQuestion1 = $('#question{QID}'); var timeQuestion2 = timeQuestion1.nextAll('.text-short:eq(0)'); var timeQuestions = $(timeQuestion1).add(timeQuestion2); // Load the timepicker JS and CSS var surveyRoot = location.pathname.split('index.php')[0]; $('<link rel="stylesheet" type="text/css" href="'+surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.css" >').appendTo('head'); $.getScript(surveyRoot+'third_party/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.js', function() { // Okay, JS is loaded...initialize the Q1 timepicker $('input[type="text"]', timeQuestion1).timepicker({ timeFormat: "HH:mm", showTime: true, onClose: function() { checkconditions(this.value, this.name, this.type); q2Timepicker(this.value); $('button.ui-datepicker-current').show(); $(this).blur(); } }); if($('input[type="text"]', timeQuestion1).val() != '') { q2Timepicker($('input[type="text"]', timeQuestion1).val()); } }); // Hide the "Now" button and enforce using the timepicker $('input[type="text"]', timeQuestions).attr('readonly', 'readonly').on('click focus', function() { $('button.ui-datepicker-current').hide(); $("#ui-datepicker-div").position({ my: "left top", at: "left-3 top-3", of: $(this) }); }); // A function to reset Q2 and initialize a timepicker function q2Timepicker(q1Time) { var q1Hours = q1Time.split(':')[0]; var minHours = Number(q1Hours) + 1; var q2Hours = ''; if($('input[type="text"]', timeQuestion2).val() != '') { q2Hours = $('input[type="text"]', timeQuestion2).val().split(':')[0]; } if(q1Hours >= q2Hours) { $('input[type="text"]', timeQuestion2).val(''); } $('input[type="text"]', timeQuestion2).timepicker('destroy').timepicker({ timeFormat: "HH:mm", hourMin: minHours, showTime: true, onClose: function() { checkconditions(this.value, this.name, this.type); $('button.ui-datepicker-current').show(); $(this).blur(); } }); } }); </script>