javascript - Is there any option to change locale in sap.m.Datepicker? -
sap.ui.commons.datepicker has property "locale" set language of datepicker.but dont find property such in "sap.m.datepicker" change locale.is there possible way can done?
there no direct property locale in datepicker. however, there clumsy trick overcome this, , unfortunately uses private attribute "_odisplayformat", stores instance of sap.ui.core.format.dateformat. snippet demonstrating below:
<!doctype html> <html> <head> <meta name="description" content="ui5 datepicker non-default locale"/> <meta http-equiv='x-ua-compatible' content='ie=edge' /> <meta http-equiv='content-type' content='text/html;charset=utf-8'/> <title>ui5 datepicker example different locales</title> <script id='sap-ui-bootstrap' type='text/javascript' src='https://openui5.hana.ondemand.com/resources/sap-ui-core.js' data-sap-ui-theme='sap_bluecrystal' data-sap-ui-libs='sap.m,sap.ui.core'> </script> <script> var ovbox = new sap.m.vbox({ width: "50%"}); var ofrenchformat; var oenglishformat; var odatepicker = new sap.m.datepicker({ dateformat: "long" }); odatepicker.setvalue(new date()); ovbox.additem(odatepicker); ovbox.additem(new sap.m.button({ text: "set french locale", press: function(oevent) { if (!ofrenchformat) { ofrenchformat = sap.ui.core.format.dateformat.getdateinstance({ style: "full"}, new sap.ui.core.locale("fr_fr")); } var odate = odatepicker.getvalue(); odatepicker._odisplayformat = ofrenchformat; odatepicker.setdisplayformat("long"); odatepicker.setvalue(odate); } })); ovbox.additem(new sap.m.button({ text: "set locale", press: function(oevent) { if (!oenglishformat) { oenglishformat = sap.ui.core.format.dateformat.getdateinstance({ style: "full"}, new sap.ui.core.locale("en_us")); } var odate = odatepicker.getvalue(); odatepicker._odisplayformat = oenglishformat; odatepicker.setdisplayformat("long"); odatepicker.setvalue(odate); } })); ovbox.placeat("content"); </script> </head> <body class="sapuibody" id="content"> </body> </html>
Comments
Post a Comment