dynamicaly set minDate to datepicker

Questionsdynamicaly set minDate to datepicker
David asked 4 years ago

Hi Abu,

can i use dynamicaly minDate to datepicker inside add/edit form ?

when insert or edit a record i need the new record can't have date less then max(date) from grid.

using formatoptions "opts" => mindate work but it restrict mindate to search too.

if i try to bind dynamicaly mindate to datepicker in aftershowform event it work only if i remove formatter = date from colmodels.


2 Answers
Abu Ghufran answered 4 years ago

Thanks for sharing.

David answered 4 years ago

I find how to do this

In case of someone need this functionality,

$col = array();
$col["title"] = "Date";
$col["name"] = "date";
$col["editable"] = true;

//– Recreate date formatter for edit with srcformat , newformat and minDate
$col["formatter"] = "function(cellvalue, options, rowObject){
Ndate = Date.parse(cellvalue); //– Need dateJS from http://www.datejs.com/
return $.datepicker.formatDate('dd-mm-yy', Ndate);
$col["editoptions"] = array("defaultValue"=>date('d-m-Y') );
$col["editoptions"]["dataInit"] = "function(el){
dateFormat: 'dd-mm-yy',
minDate: new Date('2016-08-01'),// must be in yy-mm-dd
showOn: 'button'
icons: {
primary: 'ui-icon-calendar'
}).attr('autocomplete', 'false');

//– Recreate date formatter for search without minDate
$col["searchoptions"]["dataInit"] = "function(el){
dateFormat: 'dd-mm-yy'
}).attr('autocomplete', 'false');
$cols[] = $col;

Your Answer

1 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?