jqgrid and datepicker control giving error for new records - jquery-ui

i binded by jqgrid with json returned from ajax. json has date in following format
11/1/2013 12:00:00 AM
in the colmodel i have specified the following
{ name: 'datecol', index: 'SignDate', width: '200', jsonmap: 'cell.SignDate', editable: true, sorttype: 'date',
editable: true, formatter: 'date', formatoptions: {
srcformat: 'm-d-Y H:i:s',
newformat: 'Y-M-d'
},
editoptions: { dataInit: initDateEdit },
initDateEdit = function(elem) {
setTimeout(function() {
$(elem).datepicker({
formatter: 'date', formatoptions: {
srcformat: 'm-d-Y H:i:s',
newformat: 'yy-M-d'
}
autoSize: true,
showOn: 'button', // it dosn't work in searching dialog
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
//$(elem).focus();
},100);
}
This displays the date correctly in the grid as
2013-Nov-01
but when i hit addnew record, the popup comes and when i select the date and hit submit, in the grid, the new record is showing
NaN-undefined-NaN
in the date column. what is wrong here?
when I use the same code as given in this link
http://www.ok-soft-gmbh.com/jqGrid/LocalFormEditing.htm
edit works fine, but when i add new row, the date comes as NaN-undefined-NaN
please help.

I think that the reason of the problem which you described is wrong parameters of jQuery UI Datepicker which you use. You use formatter and formatoptions parameters of datepicker which not exists. Instead of that you should use dateFormat option which format described here.
UPDATED: The main reason of the problem which you describe is wrong date format which you use. It's important to understand that srcformat and newformat of formatoptions should have PHP date format, but jQuery UI Datepicker supports another format which described here for example. The input data 11/1/2013 12:00:00 AM contains both date and time. On the other side jQuery UI Datepicker support date only. Because you use newformat: 'yy-M-d' then I suppose that you want just ignore the time part of the date. In the case I would suggest you to use
formatter: 'date',
formatoptions: {
srcformat: 'm/d/Y',
newformat: 'Y-m-d'
}
instead of
formatter: 'date',
formatoptions: {
srcformat: 'm-d-Y H:i:s',
newformat: 'Y-m-d'
}
which you use currently. Next problem is the dateFormat option of jQuery UI Datepicker. You have to use format which corresponds srcformat, but which uses correct format (described here). In case of srcformat: 'm/d/Y' you should use dateFormat: 'm/d/yy' instead of dateFormat: 'yy-m-dd' which you use in your jsfiddle demo.
The modified demo works now correctly.

Related

Dateformat in Jqgrid not working

I am trying to search on the date field and I used the below code for the search datepicker, I need the date to be displayed as dd-M-yy format but in the search it shows as ddMyy omitting the '-' in between. Can you please suggest me the
DateSearch = function (elem) {
setTimeout(function () {
$(elem).datepicker({
dateFormat: 'dd-M-yy',
autoSize: true,
changeYear: true,
changeMonth: true,
showWeek: true,
showButtonPanel: true
})
}, 100);
}
current appearance
Any help in this regards will be greatly appreciated.

How to dynamically set properties for AngularJS jQueryUI datepicker directive

I have a need to set the min Date for one of my datepicker inputs to 5 days after today's date. I have setup the jQueryUI datepicker directive for AngularJS, and by itself, it works great. When I try to add any properties to the input for an individual datepicker, such as 'min' (Date), it does not appear to honor the property, and shows me all dates.
sorry for not having a jsfiddle or plunker
EDIT: Updated to show solution
index.html
<input id="requestDate" type="text" ng-model="requestDate" ss-datepicker min-date="5"/>
Datepicker.js
app.directive('ssDatepicker', function(){
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl){
$(function(){
element.datepicker({
dateFormat:'dd-M-yy',
showOn: 'both',
buttonImage: "/e/images/calendar-ui.gif",
buttonImageOnly: true,
buttonText:'Choose a Date',
beforeShow: function(element, datepicker){
if(attrs.minDate){
angular.element(element).datepicker("option", "minDate", attrs.minDate);
}
if(attrs.maxDate){
angular.element(element).datepicker("option", "maxDate", attrs.maxDate);
}
},
onSelect:function(date){
scope.$apply(function(){
ngModelCtrl.$setViewValue(date);
});
}
});
});
}
}
});
Thanks in advance!
Okay, thanks to Sebastian, I was able to figure it out. It doesn't, for some reason, like a date variable for the "min-date" attribute, but it will accept the offset, which, for my purposes, works exactly as needed. I am fairly sure that it is a formatting problem with the date that prevented it from working.
app.directive('ssDatepicker', function(){
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl){
$(function(){
element.datepicker({
dateFormat:'dd-M-yy',
showOn: 'both',
buttonImage: "/e/images/calendar-ui.gif",
buttonImageOnly: true,
buttonText:'Choose a Date',
beforeShow: function(element, datepicker){
if(attrs.minDate){
angular.element(element).datepicker("option", "minDate", attrs.minDate);
}
if(attrs.maxDate){
angular.element(element).datepicker("option", "maxDate", attrs.maxDate);
}
},
onSelect:function(date){
scope.$apply(function(){
ngModelCtrl.$setViewValue(date);
});
}
});
});
}
}
});
How do you thing the "min" value should led to some changes?
Your directive doesn't read this value, does it?
You can access it via attrs.min in your link function.
Have you got some documentation for what you are doing. I can't find something, that looks like your code.
Oh - you are not using Angular UI Bootstrap Datepicker but jQuery UI Datepicker.
So you have to set this value: http://api.jqueryui.com/datepicker/#option-minDate
...
dateFormat:'dd-M-yy',
showOn: 'both',
buttonImage: "/e/images/calendar-ui.gif",
buttonImageOnly: true,
buttonText:'Choose a Date',
minDate: attrs.min, // get the value of the "min" attribute - maybe you should take care that it is really a date
...
Just like: http://plnkr.co/edit/MyduNfrchgsuD9mAYOEU?p=preview

jqueryUI datePicker constructor

Can someone explain me how to create a jquery UI datepicker with both properties changeMonth and localization?
I have these two lines of code:
$('.datePicker').datepicker($.datepicker.regional['en']);
$('.datePicker').datepicker({ changeMonth: true });
I'd like to merge them into a single line, since the second one seems to fail if not called when and only when constructing the datepicker for the first time. Unfortunately, I can't do this since I don't know to which property assign the $.datepicker.regional['en'].
Thanks.
I've already tried this, with no success: jQueryUI datepicker: Month/Year Menus with Localization
var obj = $.extend($.datepicker.regional['en'], { changeMonth: true, other settings... })
$('.datePicker').datepicker(obj);
Using jquery $.extend, we can combine both the settings object and the localizator object.
You can set any number of properties after you initialize the datapicker as follows:-
$.datepicker.setDefaults({
showOn: "both",
buttonImageOnly: true,
buttonImage: "calendar.gif",
buttonText: "Calendar"
});

jQuery-Timepicker-Addon removes the time on preloaded dates

I am trying to use the jQuery-Timepicker-Addon by Trent Richardson and have maybe found a bug but figured I'd post here to see if anyone sees something I am doing wrong.
I have a start date/time and end date/time field and am trying to sync them to update minDate/maxDate depending on selections. These two text fields may be populated already when the page loads which appears to be causing me a problem.
Here is a working example of my problem: http://jsfiddle.net/eQmsw/3/
Here is the code inline:
<input id="start" type="text" size="30" value="11/14/2012 02:45 PM" /> <input id="end" type="text" size="30" value="11/28/2012 12:00 AM" />​
$(function() {
var startDate = new Date(2012,10,14,14,45,0,0);
var endDate = new Date(2012,10,28,0,0,0,0);
var startDatePicker = $('#start');
var endDatePicker = $('#end');
startDatePicker.datetimepicker({
defaultDate: startDate,
maxDate: endDate,
showButtonPanel: true,
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
ampm: true,
stepMinute: 15,
timeFormat: 'hh:mm TT',
onSelect: function(selectedDateTime) {
var minDate = startDatePicker.datetimepicker('getDate');
endDatePicker.datetimepicker('option', 'minDate', minDate);
}
});
endDatePicker.datetimepicker({
defaultDate: endDate,
minDate: startDate,
showButtonPanel: true,
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
ampm: true,
stepMinute: 15,
timeFormat: 'hh:mm TT',
onSelect: function(selectedDateTime) {
var maxDate = endDatePicker.datetimepicker('getDate');
startDatePicker.datetimepicker('option', 'maxDate', maxDate);
}
});
});​
If you change one date, the other's time is removed. Once you have changed one date though, and fixed the other with the time removed, all other changes work as expected. I'm setting the 'defaultDate' property of each to a date the corresponds to it's initial value. In real life, I actually parse the date string but thought this would be clearer.
I will also post this in the issues list on the github site for the project but wanted to get this in front of the most people.
Thanks in advance for any help!
Well, I found something that works. I guess the 'defaultDate' option doesn't work as I was expecting. If it set the date on the datetimepicker after initialization, it works.
startDatePicker.datetimepicker('setDate', startDate);
endDatePicker.datetimepicker('setDate', endDate);

datepicker common options but different altField altFormat

Using jquery-ui datepicker
I would like to use altField and altFormat to 2 datepickers on the same page but I can't figure out how to add these 2 options which are specific to each datepicker along with my common set of options.
Code sample below. #dt1 does not work, but #dt2 works. How can I get #dt1 to work while using the datepickerOpts?
var datepickerOpts = {
minDate: -2,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
};
$('#dt1').datepicker(datepickerOpts,
{altField: '#alt1',
altFormat: 'mm-dd-yy'
});
$('#dt2').datepicker({
minDate: -2,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
altField: '#alt2',
altFormat: '#'
});
You passed in altField and altFormat as one array option in #dt1, but you did put them as 2 different options in #dt2 (which is the right way). What you have to do is make a copy of the opts(in case you add new elements in the future) for dt1 and dt2, append the altField altFormat as part of the datepickerOpts, and pass them as the only option to datepicker initialization.

Resources