jQuery UI datepicker (with time addon) issues -


i'm trying implement jquery ui date picker time picker addon (http://trentrichardson.com/examples/timepicker/)

for reason, i'm getting nan instead of numbers , little slider isn't showing up. downloaded redmound theme ui, might have it? i've copied code demo website.

any ideas?

here's site i'm trying working on:

http://citysouthphysio.website.2010.360southclients.com/book-appointment.html

the code is:

jquery('#date').datetimepicker({     duration: '',     dateformat: 'dd-mm-yy',     ampm: true,     hourmin: 8,     hourmax: 16 }); 

and jquery timepicker js is:

/* * jquery timepicker addon * by: trent richardson [http://trentrichardson.com] * version 0.6.2 * last modified: 9/26/2010 *  * copyright 2010 trent richardson * dual licensed under mit , gpl licenses. * http://trentrichardson.com/impromptu/gpl-license.txt * http://trentrichardson.com/impromptu/mit-license.txt *  * heres css: * .ui-timepicker-div dl{ text-align: left; } * .ui-timepicker-div dl dt{ height: 25px; } * .ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; } */  (function($) {     function timepicker(singleton) {         if(typeof(singleton) === 'boolean' && singleton == true) {             this.regional = []; // available regional settings, indexed language code             this.regional[''] = { // default regional settings                 currenttext: 'now',                 ampm: false,                 timeformat: 'hh:mm tt',                 timeonlytitle: 'choose time',                 timetext: 'time',                 hourtext: 'hour',                 minutetext: 'minute',                 secondtext: 'second'             };             this.defaults = { // global defaults datetime picker instances                 showbuttonpanel: true,                 timeonly: false,                 showhour: true,                 showminute: true,                 showsecond: false,                 showtime: true,                 stephour: 0.05,                 stepminute: 0.05,                 stepsecond: 0.05,                 hour: 0,                 minute: 0,                 second: 0,                 hourmin: 0,                 minutemin: 0,                 secondmin: 0,                 hourmax: 23,                 minutemax: 59,                 secondmax: 59,                 alwayssettime: true             };             $.extend(this.defaults, this.regional['']);         } else {             this.defaults = $.extend({}, $.timepicker.defaults);         }      }      timepicker.prototype = {         $input: null,         $timeobj: null,         inst: null,         hour_slider: null,         minute_slider: null,         second_slider: null,         hour: 0,         minute: 0,         second: 0,         ampm: '',         formatteddate: '',         formattedtime: '',         formatteddatetime: '',          //########################################################################         // add our sliders calendar         //########################################################################         addtimepicker: function(dp_inst) {             var tp_inst = this;             var currdt = this.$input.val();             var regstr = this.defaults.timeformat.tostring()                 .replace(/h{1,2}/ig, '(\\d?\\d)')                 .replace(/m{1,2}/ig, '(\\d?\\d)')                 .replace(/s{1,2}/ig, '(\\d?\\d)')                 .replace(/t{1,2}/ig, '(am|pm|a|p)?')                 .replace(/\s/g, '\\s?') + '$';              if (!this.defaults.timeonly) {                 //the time should come after x number of characters , space.  x = @ least length of text specified date format                 var dp_dateformat = $.datepicker._get(dp_inst, 'dateformat');                 regstr = '.{' + dp_dateformat.length + ',}\\s+' + regstr;             }              var order = this.getformatpositions();             var treg = currdt.match(new regexp(regstr, 'i'));              if (treg) {                 if (order.t !== -1) {                     this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ? '' : (treg[order.t].charat(0).touppercase() == 'a') ? 'am' : 'pm').touppercase();                 }                  if (order.h !== -1) {                     if (this.ampm == 'am' && treg[order.h] == '12') {                         // 12am = 0 hour                         this.hour = 0;                     } else if (this.ampm == 'pm' && treg[order.h] != '12') {                         // 12pm = 12 hour, other pm = hour + 12                         this.hour = (parsefloat(treg[order.h]) + 12).tofixed(0);                     } else {                         this.hour = treg[order.h];                     }                 }                  if (order.m !== -1) {                     this.minute = treg[order.m];                 }                  if (order.s !== -1) {                     this.second = treg[order.s];                 }             }              tp_inst.timedefined = (treg) ? true : false;              if (typeof(dp_inst.stay_open) !== 'boolean' || dp_inst.stay_open === false) {             // wait datepicker create itself.. 60% of time works every time..                 settimeout(function() {                     tp_inst.injecttimepicker(dp_inst, tp_inst);                 }, 10);             } else {                 tp_inst.injecttimepicker(dp_inst, tp_inst);             }          },          //########################################################################         // figure out position of time elements.. cause js cant named captures         //########################################################################         getformatpositions: function() {             var finds = this.defaults.timeformat.tolowercase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2})/g);             var orders = { h: -1, m: -1, s: -1, t: -1 };              if (finds) {                 (var = 0; < finds.length; i++) {                     if (orders[finds[i].tostring().charat(0)] == -1) {                         orders[finds[i].tostring().charat(0)] = + 1;                     }                 }             }              return orders;         },          //########################################################################         // generate , inject html timepicker ui datepicker         //########################################################################         injecttimepicker: function(dp_inst, tp_inst) {             var $dp = dp_inst.dpdiv;             var opts = tp_inst.defaults;              // added peter medeiros:             // - figure out hour/minute/second max should based on step values.             // - example: if stepminute 15, minmax 45.             var hourmax = opts.hourmax - (opts.hourmax % opts.stephour);             var minmax  = opts.minutemax - (opts.minutemax % opts.stepminute);             var secmax  = opts.secondmax - (opts.secondmax % opts.stepsecond);              // prevent displaying twice             if ($dp.find("div#ui-timepicker-div-"+ dp_inst.id).length === 0) {                 var nodisplay = ' style="display:none;"';                 var html =                     '<div class="ui-timepicker-div" id="ui-timepicker-div-'+ dp_inst.id +'"><dl>' +                         '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_'+ dp_inst.id +'"'    + ((opts.showtime)   ? '' : nodisplay) + '>'+ opts.timetext +'</dt>' +                         '<dd class="ui_tpicker_time" id="ui_tpicker_time_'+ dp_inst.id +'"'    + ((opts.showtime)   ? '' : nodisplay) + '></dd>' +                         '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_'+ dp_inst.id +'"'   + ((opts.showhour)   ? '' : nodisplay) + '>'+ opts.hourtext +'</dt>' +                         '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_'+ dp_inst.id +'"'    + ((opts.showhour)   ? '' : nodisplay) + '></dd>' +                         '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_'+ dp_inst.id +'"'    + ((opts.showminute) ? '' : nodisplay) + '>'+ opts.minutetext +'</dt>' +                         '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_'+ dp_inst.id +'"'    + ((opts.showminute) ? '' : nodisplay) + '></dd>' +                         '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_'+ dp_inst.id +'"'    + ((opts.showsecond) ? '' : nodisplay) + '>'+ opts.secondtext +'</dt>' +                         '<dd class="ui_tpicker_second" id="ui_tpicker_second_'+ dp_inst.id +'"'    + ((opts.showsecond) ? '' : nodisplay) + '></dd>' +                     '</dl></div>';                 $tp = $(html);                  // if want time picker...                 if (opts.timeonly === true) {                     $tp.prepend(                         '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' +                             '<div class="ui-datepicker-title">'+ opts.timeonlytitle +'</div>' +                         '</div>');                     $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();                 }                  tp_inst.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_inst.id).slider({                     orientation: "horizontal",                     value: tp_inst.hour,                     min: opts.hourmin,                     max: hourmax,                     step: opts.stephour,                     slide: function(event, ui) {                         tp_inst.hour_slider.slider( "option", "value", ui.value );                         tp_inst.ontimechange(dp_inst, tp_inst);                     }                 });                  // updated peter medeiros:                 // - pass in event , ui instance slide function                 tp_inst.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_inst.id).slider({                     orientation: "horizontal",                     value: tp_inst.minute,                     min: opts.minutemin,                     max: minmax,                     step: opts.stepminute,                     slide: function(event, ui) {                         // update global minute slider instance value current slider value                         tp_inst.minute_slider.slider( "option", "value", ui.value );                         tp_inst.ontimechange(dp_inst, tp_inst);                     }                 });                  tp_inst.second_slider = $tp.find('#ui_tpicker_second_'+ dp_inst.id).slider({                     orientation: "horizontal",                     value: tp_inst.second,                     min: opts.secondmin,                     max: secmax,                     step: opts.stepsecond,                     slide: function(event, ui) {                         tp_inst.second_slider.slider( "option", "value", ui.value );                         tp_inst.ontimechange(dp_inst, tp_inst);                     }                 });                  $dp.find('.ui-datepicker-calendar').after($tp);                  tp_inst.$timeobj = $('#ui_tpicker_time_'+ dp_inst.id);                  if (dp_inst !== null) {                     var timedefined = tp_inst.timedefined;                     tp_inst.ontimechange(dp_inst, tp_inst);                     tp_inst.timedefined = timedefined;                 }             }         },          //########################################################################         // when slider moves..         // on time change called when time updated in text field         //########################################################################         ontimechange: function(dp_inst, tp_inst) {             var hour   = tp_inst.hour_slider.slider('value');             var minute = tp_inst.minute_slider.slider('value');             var second = tp_inst.second_slider.slider('value');             var ampm = (hour < 12) ? 'am' : 'pm';             var haschanged = false;              // if update done in input field, field should not updated.             // if update done using sliders, update input field.             if (tp_inst.hour != hour || tp_inst.minute != minute || tp_inst.second != second || (tp_inst.ampm.length > 0 && tp_inst.ampm != ampm)) {                 haschanged = true;             }              tp_inst.hour = parsefloat(hour).tofixed(0);             tp_inst.minute = parsefloat(minute).tofixed(0);             tp_inst.second = parsefloat(second).tofixed(0);             tp_inst.ampm = ampm;              tp_inst.formattime(tp_inst);             tp_inst.$timeobj.text(tp_inst.formattedtime);              if (haschanged) {                 tp_inst.updatedatetime(dp_inst, tp_inst);                 tp_inst.timedefined = true;             }         },          //########################################################################         // format time pretty...         //########################################################################         formattime: function(tp_inst) {             var tmptime = tp_inst.defaults.timeformat.tostring();             var hour12 = ((tp_inst.ampm == 'am') ? (tp_inst.hour) : (tp_inst.hour % 12));             hour12 = (hour12 === 0) ? 12 : hour12;              if (tp_inst.defaults.ampm === true) {                 tmptime = tmptime.tostring()                     .replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12)                     .replace(/h/g, hour12)                     .replace(/mm/g, ((tp_inst.minute < 10) ? '0' : '') + tp_inst.minute)                     .replace(/m/g, tp_inst.minute)                     .replace(/ss/g, ((tp_inst.second < 10) ? '0' : '') + tp_inst.second)                     .replace(/s/g, tp_inst.second)                     .replace(/tt/g, tp_inst.ampm.touppercase())                     .replace(/tt/g, tp_inst.ampm.tolowercase())                     .replace(/t/g, tp_inst.ampm.charat(0).touppercase())                     .replace(/t/g, tp_inst.ampm.charat(0).tolowercase());              } else {                 tmptime = tmptime.tostring()                     .replace(/hh/g, ((tp_inst.hour < 10) ? '0' : '') + tp_inst.hour)                     .replace(/h/g, tp_inst.hour)                     .replace(/mm/g, ((tp_inst.minute < 10) ? '0' : '') + tp_inst.minute)                     .replace(/m/g, tp_inst.minute)                     .replace(/ss/g, ((tp_inst.second < 10) ? '0' : '') + tp_inst.second)                     .replace(/s/g, tp_inst.second);                 tmptime = $.trim(tmptime.replace(/t/gi, ''));             }              tp_inst.formattedtime = tmptime;             return tp_inst.formattedtime;         },          //########################################################################         // update our input new date time..         //########################################################################         updatedatetime: function(dp_inst, tp_inst) {             //var dt = this.$input.datepicker('getdate');             var dt = new date(dp_inst.selectedyear, dp_inst.selectedmonth, dp_inst.selectedday);             var datefmt = $.datepicker._get(dp_inst, 'dateformat');             var formatcfg = $.datepicker._getformatconfig(dp_inst);             this.formatteddate = $.datepicker.formatdate(datefmt, (dt === null ? new date() : dt), formatcfg);             var formatteddatetime = this.formatteddate;             var timeavailable = dt !== null && tp_inst.timedefined;              if(this.defaults.timeonly === true){                 formatteddatetime = this.formattedtime;             }             else if (this.defaults.timeonly !== true && (this.defaults.alwayssettime || timeavailable)) {                 formatteddatetime += ' ' + this.formattedtime;             }              this.formatteddatetime = formatteddatetime;             this.$input.val(formatteddatetime);             this.$input.trigger("change");         },          setdefaults: function(settings) {             extendremove(this.defaults, settings || {});             return this;         }     };      //########################################################################     // extend timepicker datepicker     //########################################################################             jquery.fn.datetimepicker = function(o) {         var opts = (o === undefined ? {} : o);         var input = $(this);         var tp = new timepicker();         var inlinesettings = {};          (var attrname in tp.defaults) {             var attrvalue = input.attr('time:' + attrname);             if (attrvalue) {                 try {                     inlinesettings[attrname] = eval(attrvalue);                 } catch (err) {                     inlinesettings[attrname] = attrvalue;                 }             }         }         tp.defaults = $.extend(tp.defaults, inlinesettings);          var beforeshowfunc = function(input, inst) {             tp.hour = tp.defaults.hour;             tp.minute = tp.defaults.minute;             tp.second = tp.defaults.second;             tp.ampm = '';             tp.$input = $(input);             tp.inst = inst;             tp.addtimepicker(inst);             if ($.isfunction(opts.beforeshow)) {                 opts.beforeshow(input, inst);             }         };          var onchangemonthyearfunc = function(year, month, inst) {             // update time : prevents time disappearing input field.             tp.updatedatetime(inst, tp);             if ($.isfunction(opts.onchangemonthyear)) {                 opts.onchangemonthyear(year, month, inst);             }         };          var onclosefunc = function(datetext, inst) {             if(tp.timedefined === true && input.val() != '') {                 tp.updatedatetime(inst, tp);             }             if ($.isfunction(opts.onclose)) {                 opts.onclose(datetext, inst);             }         };          tp.defaults = $.extend({}, tp.defaults, opts, {             beforeshow: beforeshowfunc,             onchangemonthyear: onchangemonthyearfunc,             onclose: onclosefunc,             timepicker: tp // add timepicker property of datepicker: $.datepicker._get(dp_inst, 'timepicker');         });          $(this).datepicker(tp.defaults);      };      //########################################################################     // shorthand use timepicker..     //########################################################################     jquery.fn.timepicker = function(opts) {         opts = $.extend(opts, { timeonly: true });         $(this).datetimepicker(opts);     };      //########################################################################     // bad hack :/ override datepicker doesnt close on select     // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378     //########################################################################     $.datepicker._base_selectdate = $.datepicker._selectdate;     $.datepicker._selectdate = function (id, datestr) {         var target = $(id);         var inst = this._getinst(target[0]);         var tp_inst = $.datepicker._get(inst, 'timepicker');          if(tp_inst){             inst.inline = true;             inst.stay_open = true;             $.datepicker._base_selectdate(id, datestr);             inst.stay_open = false;             inst.inline = false;             this._notifychange(inst);             this._updatedatepicker(inst);         }         else{             $.datepicker._base_selectdate(id, datestr);         }     };      //#############################################################################################     // second bad hack :/ override datepicker triggers event when changing input field     // , not redraw datepicker on every selectdate event     //#############################################################################################     $.datepicker._base_updatedatepicker = $.datepicker._updatedatepicker;     $.datepicker._updatedatepicker = function(inst) {         if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {             this._base_updatedatepicker(inst);             // reload time control when changing in input text field.             this._beforeshow(inst.input, inst);         }     };      $.datepicker._beforeshow = function(input, inst) {         var beforeshow = this._get(inst, 'beforeshow');         if (beforeshow) {             inst.stay_open = true;             beforeshow.apply((inst.input ? inst.input[0] : null), [inst.input, inst]);             inst.stay_open = false;         }     };      //#######################################################################################     // third bad hack :/ override datepicker allows spaces , colan in input field     //#######################################################################################     $.datepicker._base_dokeypress = $.datepicker._dokeypress;     $.datepicker._dokeypress = function(event) {         var inst = $.datepicker._getinst(event.target);         var tp_inst = $.datepicker._get(inst, 'timepicker');          if(tp_inst){             if ($.datepicker._get(inst, 'constraininput')) {                 var datechars = $.datepicker._possiblechars($.datepicker._get(inst, 'dateformat'));                 var chr = string.fromcharcode(event.charcode === undefined ? event.keycode : event.charcode);                 var chrl = chr.tolowercase();                 // keycode == 58 => ":"                 // keycode == 32 => " "                 return event.ctrlkey || (chr < ' ' || !datechars || datechars.indexof(chr) > -1 || event.keycode == 58 || event.keycode == 32 || chr == ':' || chr == ' ' || chrl == 'a' || chrl == 'p' || charl == 'm');             }         }         else{             return $.datepicker._base_dokeypress(event);         }      };      //#######################################################################################     // override "today" button grab time.     //#######################################################################################     $.datepicker._base_gototoday = $.datepicker._gototoday;     $.datepicker._gototoday = function(id) {         $.datepicker._base_gototoday(id);          var target = $(id);         var dp_inst = this._getinst(target[0]);         var tp_inst = $.datepicker._get(dp_inst, 'timepicker');          if(tp_inst){             var date = new date();             var hour = date.gethours();             var minute = date.getminutes();             var second = date.getseconds();              //check if within min/max times..             if( (hour < tp_inst.defaults.hourmin || hour > tp_inst.defaults.hourmax) || (minute < tp_inst.defaults.minutemin || minute > tp_inst.defaults.minutemax) || (second < tp_inst.defaults.secondmin || second > tp_inst.defaults.secondmax) ){                                     hour = tp_inst.defaults.hourmin;                 minute = tp_inst.defaults.minutemin;                 second = tp_inst.defaults.secondmin;                             }              tp_inst.hour_slider.slider('value', hour );             tp_inst.minute_slider.slider('value', minute );             tp_inst.second_slider.slider('value', second );              tp_inst.ontimechange(dp_inst, tp_inst);         }     };      //#######################################################################################     // jquery extend ignores nulls!     //#######################################################################################     function extendremove(target, props) {         $.extend(target, props);         (var name in props)             if (props[name] == null || props[name] == undefined)                 target[name] = props[name];         return target;     };      $.timepicker = new timepicker(true); // singleton instance })(jquery); 

i had put script inside joomla, conflicting mootools. removed mootools , works now.

if else using inside joomla, here's how remove mootools template.

$user =& jfactory::getuser(); if ($user->get('guest') == 1) {     $headerstuff = $this->getheaddata();     $headerstuff['scripts'] = array();     $this->setheaddata($headerstuff);  }; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -