JQuery Datepicker - how to get / read default settings

I want to use jQuery datepicker only for parsing and formatting dates, but on my actual page I don't want to use any datepicker.

Now I set the default datepicker values, for example.

$.datepicker.setDefaults($.datepicker.regional["de-DE"]); 

Now my question is: how to read this default date format without any datepicker object? Thinking of something like ...

 $.datepicker.getDefaults('dateFormat'); 

... returning the string "dd.MM.yyyy" to me - maybe?

+4
source share
3 answers

Current defaults are stored in $.datepicker._defaults , at least in JQuery UI 1.11. Of course, since this is an undocumented internal variable, it can be changed.

Alternatively, save a separate region variable that contains the region value. When you call setDefaults , also keep the region :

 var region="de-DE"; $.datepicker.setDefaults($.datepicker.regional[region]); 

You can then query the values ​​using $.datepicker.regional[region].dateFormat , etc.

+3
source

I really don't think this is a good answer, but so I found to solve the problem. I copy the current (default) regional settings to another index - ["local"] and use it wherever I need.

If anyone has a better way to do this, feel free to post an answer.

Page loading:

 $(function () { // Default locale = en-GB $.datepicker.setDefaults($.datepicker.regional["en-GB"]); // Copying to a new index = local $.datepicker.regional["local"] = $.datepicker.regional["en-GB"]; }); 

When I need to refer to any parameter:

 var month = $.datepicker.regional["local"].monthNames[myMonth]; 

or

 var month = $.datepicker.regional.local.monthNames[myMonth]; 
+1
source

Hi, you can get it like this:

 $('#datepicker').datepicker({ beforeShowDay : function( date ) { var monthsArr = $(this).datepicker('option', 'monthNamesShort'); console.log( monthsArr ); } }); 
0
source

Source: https://habr.com/ru/post/1480889/


All Articles