Magento Admin how to disable past days, current date in datepicker


Hi Friend's

Disable past and current date selection in admin form edit/add action

Open your form.php file and add this code

Code:

$nextdate = $fieldset->addField('next_date'.$counter, 'date',
    array(
        'name'      => 'upcoming_date',
        'label'     => 'Upcomng Date',
        'class'     => 'required-entry validate-date validate-date-range date-range-custom_theme-from',
        'required'  => true,
        'image'     => $this->getSkinUrl('images/grid-cal.gif'),
        'format'    => 'YYYY-MM-dd'
    )
);
$nextdate->setAfterElementHtml("<p>Date format is <strong style='color: #FF0000;'>YYYY</strong>/<strong style='color: #FF0000;'>MM</strong>/<strong style='color: #FF0000;'>DD</strong></p>
<script type=\"text/javascript\">
//<![CDATA[
Calendar.setup({
    inputField: 'upcoming_date',
        ifFormat: '%Y-%m-%d',
        showsTime: false,
        button: 'upcoming_date_trig',
        align: 'Bl',
        singleClick : true,
        disableFunc: function(date)  {
            var now = new Date();
            //If you want to disable current date so remove below comment
            //now.setDate(now.getDate() + 1);
           
            if(date.getFullYear()   <   now.getFullYear())  { return true; }
            if(date.getFullYear()   ==  now.getFullYear())  { if(date.getMonth()    <   now.getMonth()) { return true; } }
            if(date.getMonth()      ==  now.getMonth())     { if(date.getDate()     <   now.getDate())  { return true; } }
        }
});
//]]>
</script>");

Now Flush Magento Cache and refresh page

Hope this information is helpful to you :)


2 comments:

  1. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    seo Company in India

    ReplyDelete
  2. very very amazing explaintion....many things gather about yourself...yes realy i enjoy it
    Digital Marketing company

    in Chennai

    ReplyDelete