EasyUI Forum
September 14, 2025, 09:21:25 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Init a dateBox with today  (Read 18911 times)
yamilbracho
Jr. Member
**
Posts: 64


View Profile Email
« on: July 21, 2015, 08:33:28 AM »

I would like to init a datebox with today. I do this in my ready event
Code:
  $(document).ready(function () {	
        console.log(new Date());
        $('#desde').datebox('setValue', new Date());
    });

However, in the console i got
Uncaught TypeError: Cannot read property 'options' of undefined
My html code is

   
Code:
  Desde: <input id="desde" 
                      class="easyui-datebox"
                      style="width:120px"
                      required ="required"
                      data-options="formatter:Rutinas.dateFormatter,
                                    parser:Rutinas.dateParser">

is there something i forgot ?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: July 21, 2015, 08:56:59 AM »

The datebox value should be a string. Please try this.
Code:
var v=Rutinas.dateFormatter.call($('#desde')[0],new Date());
$('#desde').datebox('setValue', v);
Logged
yamilbracho
Jr. Member
**
Posts: 64


View Profile Email
« Reply #2 on: July 21, 2015, 10:40:15 AM »

Thanks
I changed my code as your suggestion:
Code:
     var v = Rutinas.dateFormatter.call($('#desde')[0],new Date());
        console.log("v=" + v);
        $('#desde').datebox('setValue', v);

but in the console i got

Code:
v=21/07/2015
jquery.easyui.min.js:13602 Uncaught TypeError: Cannot read property 'options' of undefined

Anything else i could check?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #3 on: July 21, 2015, 07:01:29 PM »

Please check your 'formatter' and 'parser' functions carefully to see if some errors occur.
Logged
yamilbracho
Jr. Member
**
Posts: 64


View Profile Email
« Reply #4 on: July 22, 2015, 08:06:23 AM »

Thanks!
My parser and format code are working fine, those are :
Code:
   dateFormatter: function(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
       
// date format dd/mm/yyyy
        var r = (d < 10 ? ('0' + d) : d) + '/' +
                (m < 10 ? ('0' + m) : m) + '/' +
                y;
        alert("dateFormatter=" + r);   
        return r;
    },

    dateParser: function(s) {
        alert("dateParser=" + s);
        if (!s) {
            return new Date();
        }
// date format dd/mm/yyyy
        var ss = (s.split('/'));
        var d = parseInt(ss[0], 10);
        var m = parseInt(ss[1], 10);
        var y = parseInt(ss[2], 10);
       
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
            return new Date(y, m - 1, d);
        } else {
            return new Date();
        }
    },
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #5 on: July 22, 2015, 08:32:04 AM »

Here is the example http://jsfiddle.net/xyn9ym00/. It works fine.
Logged
yamilbracho
Jr. Member
**
Posts: 64


View Profile Email
« Reply #6 on: July 22, 2015, 11:51:28 AM »

Thanks a lot!!!
I don't knwo what it's going on but I cut and paste the code in my html page and does not work!!  Angry
Code:
      console.log('Before opts');
        var opts = $('#desde').datebox('options');
        console.log('Afer opts');
       
        console.log("Before setValue");
        $('#desde').datebox('setValue', opts.formatter(new Date()));       
        console.log("After setValue");

In the console I got

Before opts
jquery.easyui.min.js:6696 Uncaught TypeError: Cannot read property 'options' of undefined

So it got problems with  this line
var opts = $('#desde').datebox('options');

desde is defined as :
Code:
   Desde: <input id="desde" 
                      class="easyui-datebox"
                      style="width:120px"
                      required ="required"
                      data-options="formatter:Rutinas.dateFormatter,
                      parser:Rutinas.dateParser">

Another suggestion ?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!