New UI - Date Formatting and User Settings

Posted by Meryk on 16-Sep-2015 10:03

Hello,

I am just trying to set a date field in the new UI.

Now we need to create a date with the current user Date format, that seems to be the one stored in "My Localization Settings". Which I am doing like that :

var todayDate = kendo.toString(kendo.parseDate(new Date()), 'dd/MM/yyyy');
myDatePicker.data("kendoDatePicker").value(todayDate);

How can we get the date format of the current user? Its does not seem to be available from current user in the helper editor. The date format that we can get to is the one in "My Settings".

What is the difference between "My Settings" and "My Localization Settings"? And which one of those settings is the one we should use ?

Thank you

Meryem

Posted by Mohammed Siraj on 17-Sep-2015 05:31

Yes. To Summarize, in New UI Edit pages:

For a date field, you can directly set Date object on field. One need not convert Date object into date string literal in a particular format & then set field value with this string.

Date display formats from 'My Localization Settings', will be used to format & display Date fields in View pages alone.

In Edit pages, we are purposefully enforcing basic date formats on kendo control i.e. dd/MM/yyyy (or MM/dd/yyyy, depending on the locale).

Do you have a requirement to show Dates in a particular format even on edit pages? If yes, can you please additional details, so that we can work out a client-side scripting solution.

All Replies

Posted by Manooj Murali on 16-Sep-2015 10:19

Hi -

You should be using the "My Localization Settings". This was introduced in order to support date/time & other field settings at one single place and have support for various locales. Rollbase uses localization settings whenever it is set.

At this moment, we do not have an api to get the current user's date format.

-Thanks

Posted by Mohammed Siraj on 16-Sep-2015 10:27

As indicated by Manooj, use My Localization Settings.

Also, with respect to your other queries, there are some solutions specific to New UI pages,

At first, you can directly set Date object as value on your date picker field.

That is, myDatePicker.data("kendoDatePicker").value(new Date()); //this will suffice

If, date picker is an object field in New/Edit/Status Change page, you can also leverage rollbase api for the same.

That is, rbf_setFieldValue('date1',new Date()), where 'date1' is the integration name of your date object field.

In New UI, all field display formats will be read from 'My Localization Settings'.

In New UI, the display format patterns can also be accessed on client-side as follows:

<script>

try{

if(!rbf_isNewUI()){
throw "This script component is written specific to New UI Context.";
}



var locContext = rb.newui.page.PageContext.getPageLocalization();

rb.newui.util.logToConsole('Date format pattern -'+locContext.getDateFormat());
rb.newui.util.logToConsole('Date format (long) pattern -'+locContext.getLongDateFormat());

//how to format a date as per user's localization settings
rb.newui.util.logToConsole('Current date formatted as per users localization settings -'+
rbf_formatDate(new Date(),locContext.getLongDateFormat()));

//similarly for other formats


}
catch(err){
if(console){
console.log('Error executing script component in page. '+err);
}
}



</script>

Posted by Meryk on 16-Sep-2015 11:29

Hi Siraj, Manooj,

Thank you for the replies. This actually answers my question thanks ! :)

Now I have another issue with the dates displaying.

Actually, if I change the date Format in "My Localization Settings" to this : "21 Aug 2014" or any another Format containing months/days in letters, all the date fields are changing to this format on the View page (and List page), but not on the Edit page !

Looks like the Edit page does not accept the Letters in the dates, because if I just change it to formats like 21/08/2014 or 08/21/2014.. it is fine, the format of the date fields is changing on all pages.

Any help with that please ?

Cheers

Meryem

Posted by Mohammed Siraj on 16-Sep-2015 11:33

In Edit pages, we are purposefully enforcing basic date formats on kendo control i.e. dd/mm/yyyy or mm/dd/yyyy, depending on the locale.

It is important that you not alter this as once you submit the form, on server side, date string will not be correctly formatted.

Posted by Mohammed Siraj on 16-Sep-2015 11:34

Correction:

It is important that you not alter this as once you submit the form, on server side, date string will not be correctly parsed into a Date object.

Posted by Mohammed Siraj on 16-Sep-2015 12:02

As an FYI, to enforce kendo date field control format, see

var fieldContext = rbf_getFieldContext('date1');//where 'date1' is field integration name

if(fieldContext){

   console.log(fieldContext? fieldContext.getKendoConfig() && fieldContext.getKendoConfig().options.format : null);  

}

Posted by Meryk on 17-Sep-2015 04:02

Hi Siraj,

So if I am not mistaken, the Date Format we select in "My Localization Settings" is not applied in the Edit pages.

If it is the case, and because I am doing all this Date field setting from the Edit page, then I do not even need to set the date Field with respect to this Format , as it is not going to be interpreted correctly, and from my tests and what you said below, I understand that only "dd/MM/yyyy" and "MM//dd/yyyy" are accepted in Edit pages.

So, at the end, without doing any formatting and with just setting the date (in Edit page) normally like that :

myDatePicker.data("kendoDatePicker").value(new Date());

It is working fine, and as we click on save and get to the View page, the selected Format is applied, no matter what it is.

Am I getting it right ?

Thank you

Meryem

Posted by Mohammed Siraj on 17-Sep-2015 05:31

Yes. To Summarize, in New UI Edit pages:

For a date field, you can directly set Date object on field. One need not convert Date object into date string literal in a particular format & then set field value with this string.

Date display formats from 'My Localization Settings', will be used to format & display Date fields in View pages alone.

In Edit pages, we are purposefully enforcing basic date formats on kendo control i.e. dd/MM/yyyy (or MM/dd/yyyy, depending on the locale).

Do you have a requirement to show Dates in a particular format even on edit pages? If yes, can you please additional details, so that we can work out a client-side scripting solution.

Posted by Meryk on 17-Sep-2015 07:46

Hi Siraj,

Thank you. Well as long as there is a standard respected in displaying these dates, it is fine it actually looks alright.

Thanks,

Meryem

This thread is closed