Reputation: 10208
I've tried every permutation of checking for this logic to work and I cannot find the right syntax.
I have the following bit of Javascript:
var d = $("#myDatepicker1").datepicker("getDate");
if ($.isEmptyObject(d)) {
$("#dailySummaryDateSelector").datepicker("setDate", new Date());
}
When the page loads and d
is evaluated Firebug shows it as Object [ ]
In the if
statement I've tried:
if (d == null) {
if (d == {}) {
if (d == Object()) {
if ($.isEmptyObject(d)) {
if (d.isEmptyObject()) {
None of these work. As far as I can tell Object [ ]
is an empty object so how do I actually test for that and get the contents of the if
statement to execute?
Upvotes: 2
Views: 10962
Reputation: 10208
For anyone that missed it my code was broken!
var d = $("#myDatepicker1").datepicker("getDate");
if ($.isEmptyObject(d)) {
$("#dailySummaryDateSelector").datepicker("setDate", new Date());
}
Should have been:
var d = $("#dailySummaryDateSelector").datepicker("getDate");
if ($.isEmptyObject(d)) {
$("#dailySummaryDateSelector").datepicker("setDate", new Date());
}
Now this works:
var d = $("#dailySummaryDateSelector").datepicker("getDate");
if (d == null) {
$("#dailySummaryDateSelector").datepicker("setDate", new Date());
}
Upvotes: 0
Reputation: 14419
getDate()
Returns: Date
Returns the current date for the datepicker or null if no date has been selected. This method does not accept any arguments.
if($("#myDatepicker1").datepicker("getDate") === null) {
alert("empty");
}
Upvotes: 6