-
11 Jan 2012 12:44 PM #1
Answered: Ext.Date.add and Datepicker
Answered: Ext.Date.add and Datepicker
Hello all,
I'm having some problems using the datepicker in conjuction with the Ext.Date.add function. I presently have a datepicker field for an original date, a field that accepts an interval (1 year, 4 months etc), and another datepicker field that should be populated with a new date, equal to the first date plus the interval.
There are no errors, but the value that's appearing in the final date field is doing very bizarre things. If the interval is a month amount it seems to work. However, if I try to add a year amount, it will append the amount to the end of the year (1/1/2012 becomes 1/1/20121), and if I add an amount of days, everything seems to change unpredictably.
The code in my controller is as follows
I have a feeling it has something to do with my initial date formatting, but since I'm getting and setting the values directly from the datepicker fields, I'd have thought that would not be an issue. I've already ensured that the fields have values and that the interval is the correct formatting. Thanks in advance!Code:calcNext: function(){ var form = Ext.getCmp('screentypeform'), last = form.down('#last').getValue(), interval = form.down('#interval').getValue(), next = form.down('#next'); if(!last || !interval){ return; } var intArray = interval.split(" "), amt = intArray[0], //Numeric value step = intArray[1].toLowerCase(); //Day, month or year if(step == "day" || step == "days"){ next.setValue(Ext.Date.add(last, Ext.Date.DAY, amt)); } else if(step == "month" || step == "months"){ next.setValue(Ext.Date.add(last, Ext.Date.MONTH, amt)); } else if(step == "year" || step == "years"){ next.setValue(Ext.Date.add(last, Ext.Date.YEAR, amt)); } }
-
Best Answer Posted by mitchellsimoens
In PR3 this is working for me:
What is the value of last and amt?Code:var date = new Date(), newDate = Ext.Date.add(date, Ext.Date.YEAR, 1); console.log(Ext.Date.format(newDate, 'm/d/Y'));
-
11 Jan 2012 12:57 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
In PR3 this is working for me:
What is the value of last and amt?Code:var date = new Date(), newDate = Ext.Date.add(date, Ext.Date.YEAR, 1); console.log(Ext.Date.format(newDate, 'm/d/Y'));Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Jan 2012 1:11 PM #3
Aha, amt is being interpreted as a string, since I split it from a string I guess. If I parse it into an int it works
Although I do wonder why it didn't have a problem with months...
Thanks for the assistance.
P.S. there should be a face-palm smiley face.
-
11 Jan 2012 1:44 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote
I have had many of those moments myself