⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Select date in edit mode 10 years by default



loginet
  • profile picture
  • Member

Posted 14 March 2012 - 19:44 PM

Hi,

A small problem: I have a date field in database: birthDate.
In edit mode the select box show me 10 years before and 10 years after but my poor user is 40 years old, so his birth date in in 1972. :)
How can I change this default 10 years up/down on date field?

loginet
  • profile picture
  • Member

Posted 15 March 2012 - 14:12 PM

A quick answer for newbies like me searching for this:
Actually, if you try to enter manually the date it will reset the select to 10 years up and down from your entered date.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 20 March 2012 - 21:52 PM

You can change the datapicker JavaScript for your needs at: your_project/assets/grocery_crud/js/jquery_plugins/config/jquery.datepicker.config.js

amityweb
  • profile picture
  • Member

Posted 23 July 2012 - 21:57 PM

I needed to do this, but did not want to change the core code in case of updates, so I used the following code from JQuery datapicker website in my own document ready file I have:



$(document).ready(function()
{
var changeYear = $( ".datepicker-input" ).datepicker( "option", "changeYear" );
$( ".datepicker-input" ).datepicker( "option", "yearRange", "-20:+0" );
});

deib97
  • profile picture
  • Member

Posted 20 May 2013 - 02:18 AM

same problem with me, how make it amityweb? :)


yahooman
  • profile picture
  • Member

Posted 12 February 2016 - 11:38 AM

hi loginet and deib97,

 

the simple way, just add the code from amityweb to the "jquery.datepicker.config.js" file

 

see the example below:

 

$(function(){
    $('.datepicker-input').datepicker({
            dateFormat: js_date_format,
            showButtonPanel: true,
            changeMonth: true,
            changeYear: true
    });
    
    $('.datepicker-input-clear').button();
    
    $('.datepicker-input-clear').click(function(){
        $(this).parent().find('.datepicker-input').val("");
        return false;
    });
    
    $(document).ready(function()
    {
    var changeYear = $( ".datepicker-input" ).datepicker( "option", "changeYear" );
    $( ".datepicker-input" ).datepicker( "option", "yearRange", "-50:+0" );
    });


});