Change the language of jqm DateBox plugin programmatically

1.1k views Asked by At

I’m looking for a way to programmatically change the language of the jqm DateBox plugin. I’ve included the language files in my header section:

<script type="text/javascript" src="../Scripts/jqmDateBox/jqm-datebox.core.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jqm-datebox.mode.flipbox.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.de.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.en.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.fr.utf8.js"></script>
<script type="text/javascript" src="../Scripts/jqmDateBox/jquery.mobile.datebox.i18n.it.utf8.js"></script> 

I’ve tried to change the language using the following code snippet (changeing language files in JTSage Date and Time Picker plugin for jQueryMobile):

var x = $.mobile.datebox.prototype.options.lang[newLang];
$(document).find('[data-role=datebox]').each(function () {
    $(this).data('mobileDatebox').options.lang[newLang] = x;
    $(this).data('mobileDatebox').options.useLang = "de";
});

But this gives me the following exception:

JavaScript runtime error: Unable to get property 'options' of undefined or null reference.

How can I change the language of the jqm DateBox plugin programmatically?

1

There are 1 answers

0
musium On

I’ve found a way to change the language…

setDateInputOptions($("#dateInput"), "de");
function setDateInputOptions(input, language) {
        input.datebox("option", {
            "mode": "flipbox",
            "useFocus": true,
            "useButton": false,
            "useNewStyle": true,
            "overrideDateFormat": "%d.%m.%Y",
            "overrideDateFieldOrder": ["d", "m", "y"],
            "useLang": language
        });
    }