Jump to content


Select date in edit mode 10 years by default

date edit

  • Please log in to reply
5 replies to this topic

#1 loginet

loginet

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 14 March 2012 - 07: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?

#2 loginet

loginet

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 15 March 2012 - 02: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.

#3 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 20 March 2012 - 09: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
Posted Image

#4 amityweb

amityweb

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

Posted 23 July 2012 - 09: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" );
});


#5 deib97

deib97

    Member

  • Members
  • PipPip
  • 18 posts

Posted 20 May 2013 - 02:18 AM

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



#6 yahooman

yahooman

    Newbie

  • Members
  • Pip
  • 4 posts

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" );
    });


});

 







Also tagged with one or more of these keywords: date, edit

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users