2

im still finding my way around with both jquery and JS. im using the plugin for date time picker here http://xdsoft.net/jqplugins/datetimepicker/ and i need to pass an array of allowed times in.

Basically the documentation states this

$('#datetimepicker5').datetimepicker({
 datepicker:false,
 allowTimes:[
  '12:00', '13:00', '15:00', 
  '17:00', '17:05', '17:20', '19:00', '20:00'
 ]
});

What i was wondering was is there a way to pass in an array here? Ive tried creating a function and doing allowed:getArr() but it didnt work

function getArr() {
            var allowTimes = [
  '12:00', '12:30', '13:00', '13:30', '14:00', 
  '14:30', '15:00', '15:30', '19:00', '20:00'
 ];
        return allowTimes;

    }

is this how it should be done or is it a limitation of the plugin is what im trying to figure out?

2
  • You want to get allowedTimes from #picker5 right? Commented Jan 13, 2014 at 15:38
  • Please provide your entire invocation of datetimepicker code. Commented Jan 13, 2014 at 15:38

2 Answers 2

2

It is likely you are passing allowTimes a reference to the function instead of invoking it to return the results.

If you're code looks like the following:

$('#datetimepicker5').datetimepicker({
 datepicker:false,
 allowTimes: function getArr() {
        var allowTimes = [
           '12:00', '12:30', '13:00', '13:30', '14:00', 
           '14:30', '15:00', '15:30', '19:00', '20:00'
        ];
    return allowTimes;
 }
});

You will want to change it to the following:

$('#datetimepicker5').datetimepicker({
 datepicker:false,
 allowTimes: function getArr() {
        var allowTimes = [
           '12:00', '12:30', '13:00', '13:30', '14:00', 
           '14:30', '15:00', '15:30', '19:00', '20:00'
        ];
    return allowTimes;
 }()
});
Sign up to request clarification or add additional context in comments.

1 Comment

not exactly what i implemented but got me on the right track so for that you get the kudos - thanks :)
0

I'm a little late here but I had the same problem and solved it like this: I created a comma separated string from a JSON response. Then when initializing the datetimepicker I passed the allowTimes option as follows:

$('.delivery').datetimepicker({
                datepicker:false,
                timepicker:true,
                format:'H:i',
                step:30,
                allowTimes: function getArr() {
                    var allowTimes = str_times.split(',');
                    return allowTimes;
                }()

            });
        })

Where str_times is a string like this:

str_times = "12:00,13:00,14:00,15:00"

Of course you can create this string from any type of data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.