maimoona
maimoona

Reputation: 627

JQuery easyui and Datejs date conflict

There is a conflict between jquery-easyui datebox (http://www.jeasyui.com/documentation/index.php) and Datejs api (http://www.datejs.com/). jquery-easyui version is 1.3.3 .

When both are included in any jsp page, poped up calendar's current date is always Jan, 1970. I could not find any methods that would set datebox's value to the current date (do not want to use a string default value but rather the current date should be automatically be set). I tried using following code as explained in documentation

//get the calendar object
var c = $('#dtbDueFrom').datebox('calendar');
// set the first day of week to monday
c.calendar({
    current: new Date()
});
}

but it throws the exception TypeError: $.data(...) is undefined.

$('#dtbDueFrom').datebox({current: new Date()});

This does not work either.

Datejs is a really helpful library and I cannot remove it from project as I need the methods it provides. Eliminating it works absolutely fine but is there any workaround to get both work along. Thanks.

Upvotes: 0

Views: 3429

Answers (2)

user17299084
user17299084

Reputation: 1

The Prototype-Definition "Date.now" conflicts with default Date.now(). I've renamed it to nowDjs

Date.nowDjs=function(){
  return new Date();
};

Upvotes: 0

maimoona
maimoona

Reputation: 627

I still could not find exact solution to the problem above but here is the workaround that I used to make my datebox work according to my need

Due Date <input id="dateDuetxt" class="easyui-datebox" style="width:100px"/>  

<script>

$('#dateDuetxt').datebox({
    value: (new Date().toString('dd-MMM-yyyy')), /* Date.js toString function to convert date into format that is being used by datebox. */
    formatter : function(date){
        return date.toString('dd-MMM-yyyy');
    },
    parser : function(s){
        var t = Date.parse(s);
        if (!isNaN(t)){
            return new Date(t);
        } else {
            return null;
        }
    }
});

</script>

Upvotes: 0

Related Questions