Citizen
Citizen

Reputation: 12927

Accessing jquery object without "this"

I'm using this plugin:

http://xdsoft.net/jqplugins/datetimepicker/

Here's my fiddle:

http://jsfiddle.net/DC5yT/1/

And I'm trying to use this (which works)

var logic = function( currentDateTime ){
  // 'this' is jquery object datetimepicker
  if( currentDateTime.getDay()==6 ){
    this.setOptions({
      minTime:'11:00'
    });
  }else
    this.setOptions({
      minTime:'8:00'
    });
};
jQuery('#datetimepicker_rantime').datetimepicker({
  onChangeDateTime:logic,
  onShow:logic
});

Except I'm using two calendars which affect eachother so I'd like to be able to do something like:

$("#end").setOptions({
      minTime:'8:00'
    });

But I get

setOptions is not a function

How can I select one of my date pickers without having to use "this."?

Upvotes: 0

Views: 122

Answers (2)

Goose
Goose

Reputation: 831

Access the setOptions like this

$("#end").data("xdsoft_datetimepicker").setOptions({
    minTime:'8:00'
});

I have updated your fiddle to change the end max date once the start date/time it changed.

http://jsfiddle.net/DC5yT/3/

Upvotes: 1

HaukurHaf
HaukurHaf

Reputation: 13796

Can't you just assign it as a variable?

var logic = function( currentDateTime ){
  // 'this' is jquery object datetimepicker
  if( currentDateTime.getDay()==6 ){
    this.setOptions({
      minTime:'11:00'
    });
  }else
    this.setOptions({
      minTime:'8:00'
    });
};
var dateTimePickerOne = jQuery('#datetimepicker_rantime').datetimepicker({
  onChangeDateTime:logic,
  onShow:logic
});

Then:

dateTimePickerOne.setOptions(...)

Upvotes: 1

Related Questions