Question

I am using below jquery mobile datebox plugins for date control in mobile application. It's working fine with default date format. But I want to apply date format based on current culture setting whether it's mobile phone or desktop. Based on device date format, date should be populated in the Date control.

<link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" />
 <script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.core.min.js"></script>
    <script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.calbox.min.js"></script>

I have tried with below approach.

jQuery.extend(jQuery.mobile.datebox.prototype.options.lang.default, { 'dateFormat': dformat , }); 

But it has two below mentioned limitation due to which I am unable to use this approach.
1) Not supported on iPhone 3/4 (safari 3.1.1 or below)
2) Date Format which is not compatible with Window format (it uses format like %d-%m-%y etc).

I want to utilize this plugin but it should provide the culture based date format selection.
Please provide your suggestion and let me know if you have any doubt.

Was it helpful?

Solution

Not sure if I really understood your question, but normally you could use the "override" options to inject directly the user culture. In one of my code once I detected the user culture I sue a script like below to do the work: (i update by htis way the header title, the date field order and the dateformat).

In this code the "sDateFormat" set the right pattern following the user culture. And the "currentdatefield" is a jquery variable of a date field in my web form :

currentdatefield.data("options", {
                    mode: "datebox",
                    useLang: varuserLocale,
                    useFocus: true,
                    useClearButton: true,
                    useCollapsedBut: true,
                    defaultValue: sDateForDefValue, /* defaultValue : this value must be a string formated in "yyyy-mm-dd" (not a JS object date) */
                    'overrideDateFieldOrder': DateFieldOrder,
                    'overrideHeaderFormat': vardateformat,
                    'overrideDateFormat': sDateFormat   /* Example: "%m/%d/%Y" This date format pattern is directly injected in the field linked */
                });
            });

Not sure, it's help you but perhaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top