ajanthanm / mobiscroll

Automatically exported from code.google.com/p/mobiscroll
0 stars 0 forks source link

Enable user to select >24 hours (with patch) #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This patch makes it possible to set the maximum amount of hours the user can 
select. This was useful in my scenario, in which mobiscroll was used to set the 
time in a stopwatch.

It will give you an additional 'maxHour' property, which you can set to e.g. 72 
(so the user can choose from 0-72 hours in stead of 0-24). Note: this only will 
work when 'ampm' is false and 'preset' is set to 'time'.

{{{
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ CURRENT
@@ -473,12 +473,13 @@
                     s.wheels.push(w);
                 }
                 if (s.preset.match(/time/i)) {
+                    s.maxHour  = (!s.preset.match(/date/i) && s.maxHour && 
!s.ampm) ? s.maxHour : (s.ampm ? 13 : 24); //only works in timepicker, with 24 
hours notation
                     s.stepHour = (s.stepHour < 1) ? 1 : parseInt(s.stepHour);
                     s.stepMinute = (s.stepMinute < 1) ? 1 : parseInt(s.stepMinute);
                     s.stepSecond = (s.stepSecond < 1) ? 1 : parseInt(s.stepSecond);
                     var w = {};
                     w[s.hourText] = {};
-                    for (var i = 0; i < (s.ampm ? 13 : 24); i += s.stepHour)
+                    for (var i = 0; i < s.maxHour; i += s.stepHour)
                         w[s.hourText][i] = (i < 10) ? ('0' + i) : i;
                     w[s.minuteText] = {};
                     for (var i = 0; i < 60; i += s.stepMinute)
}}}

Example of using this:

{{{
$('#date1').scroller({
    "preset": "time",
    "ampm": false,
    "seconds": true,
    "maxHour": 72,
    "timeFormat": "y-m-d HH:ii",
    "onSelect": function(text, scrollerObject) {
      console.log(scrollerObject.values); //returns e.g. [72,0,0] when user selects 72 hours
    }
  });

}}}

Original issue reported on code.google.com by koosvdk...@gmail.com on 10 Oct 2011 at 9:21

GoogleCodeExporter commented 8 years ago
This won't be included in the official release, it is possible to solve this 
with custom scrollers.

Original comment by diosla...@gmail.com on 3 Jan 2012 at 8:09