This is a migrated thread and some comments may be shown as answers.

Kendo format string puts literal '?' in the wrong place

4 Answers 295 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 12 Oct 2016, 03:09 PM

We allow users to specify custom symbols as part of the number formats they see in our software. We are using Kendo's formatting capability to incorporate these symbols as part of our format strings. For example, we might have a format string like:

var format = "\\$0.00\\/\\h\\r;(\\$0.00\\/\\h\\r)";

kendo.toString(-1.7, format); // ($1.70/hr)

Note the use of backslashes to escape literal characters in the format string. This seems to work well, except when the ? character is used. Here's an example:

var format = "\\?\\x0";

kendo.toString(100, format); // returns "x?100", but I would expect "?x100"

This definitely seems like a bug. I can't find any documentation (http://docs.telerik.com/kendo-ui/framework/globalization/numberformatting) explaining why the '?' character should receive special treatment at all, let alone when escaped.

I've also posted this as a StackOverflow question:

http://stackoverflow.com/questions/39977914/kendo-format-string-puts-literal-in-the-wrong-place

 

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 14 Oct 2016, 11:01 AM
Hello Mike,

The ? symbol does not need to be escaped, that is why this result is different from the expected one.

The following code snippet can be used to format the number in the desired way:

var format = "?x0";
console.log(kendo.toString(100, format));

In our documentation we only listed the symbols that specifically need to be escaped:

http://docs.telerik.com/kendo-ui/framework/globalization/numberformatting#custom

If there is a symbol that needs to be escaped and it is not in the list we will be happy to add this information in the documentation.

Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Mike
Top achievements
Rank 1
answered on 14 Oct 2016, 12:24 PM

Hi Stefan,

It's interesting that the bug sometimes disappears when the escaping is gone. HOWEVER, this does not solve the problem in general. Here's another example:

var format = "?\\$0";
console.log(kendo.toString(100, format)); // "$?100"

In this case, the '?' is not escaped. The '$' DOES need to be escaped per the documentation because it will be translated to the currency symbol for the current culture. Note that escaping '?' does not fix the issue:

var format = "\\?\\$0";
console.log(kendo.toString(100, format)); // "$?100"

While it isn't specifically documented that all characters support escaping, the fact that most already do is actually necessary to construct masks with other special characters like '0', ',', and '.'. Universal escaping is also critical for being able to share formats between kendo and .NET.

0
Stefan
Telerik team
answered on 18 Oct 2016, 08:03 AM
Hello Mike,

After testing the newly provided scenario, I can confirm that indeed the result is unexpected.

I created an issue in our GitHub repository and forwarded it to our developers for fixing. You can track its progress at:

https://github.com/telerik/kendo-ui-core/issues/2326

Additionally, I updated your Telerik points from bringing this to our attention.

Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Mike
Top achievements
Rank 1
answered on 18 Oct 2016, 12:53 PM
Thanks Stefan I appreciate it!
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Mike
Top achievements
Rank 1
Share this question
or