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

kendo.Slider() culture not localizing number correctly

6 Answers 164 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Baldvin
Top achievements
Rank 1
Baldvin asked on 10 Mar 2014, 12:14 PM
Hello.

I have set up my environment to include 

~/Scripts/kendo/2013.3.1324/cultures/kendo.culture.is-IS.min.js

followed by a localization script in _Layout.cshtml like this

<script type="text/javascript">
kendo.culture("@culture");
</script>

and construct a Slider in an Editor Template like so:
@model string
@(Html.Kendo().Slider()
.Name(@ViewData.ModelMetadata.PropertyName)
.Min(0.55)
.Max(34.1))
.SmallStep(0.5)
.LargeStep(5.5)
.Value(@Convert.ToDouble(Model))
)

The problem is that the tooltip will show a dot for decimal separator like "34.1" instead of the expected "34,1" (for example).

Also, when the value is read from the control it contains a dot instead of the comma. As a result, the value will come from the slider as 341 instead of 34.1 (or 34,1 in Icelandic, to be exact).

Do you have any clue what I could do differently, am I missing something or am I misunderstanding the concept of culture and decimal numbers as far as the Slider goes?

Sincerely,
Baldvin

6 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 12 Mar 2014, 12:28 PM
Hello Baldvin,

Thank you for noticing the problem with the tooltip. It seems that no formatting is applied by default and so the value is displayed as JavaScript number. We will fix this for the next official release. For now you can show the value based on the culture by specifying a format for the tooltip:
.Tooltip(tooltip => tooltip.Enabled(true).Format("{0:n}"))

Could you clarify what you mean by "when the value is read from the control"? The slider should format the value in the input as expected and if the server side and the client side cultures are the same, then the value should be bound correctly when the slider is posted with a form.



Regards,
Daniel
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Baldvin
Top achievements
Rank 1
answered on 12 Mar 2014, 03:09 PM
Thank you for this fix. It works. To clarify my comment regarding "reading the value", in fact the value does not bind correctly when the slider is posted with a form unless I apply your fix. Otherwise "34.1" will convert to 341. However, "34,1" converts correctly to 34.1 (as double in C#). We do have same culture on both the client and server side ("is-IS" in this case).
0
Daniel
Telerik team
answered on 14 Mar 2014, 09:53 AM
Hello again,

I am not sure what could be causing the value not to be posted correctly when the format is not set. The format for the tooltip is not used to set the value in the slider input. I attached a sample project using the described scenario. Please check it and let me know if I am missing something and if the value is sent as expected on your side.

Regards,
Daniel
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Stéphane
Top achievements
Rank 1
answered on 23 Mar 2016, 02:24 PM

Hello both,

I have the same problem with the value not being read correctly. I have tried two ways of creating the slider : Test and Test2

<input data-role="slider" id="Test" max="2.2" min="0.5" name="Test" step="0.05" value="1.3" type="text"><br/>
@(Html.Kendo().Slider()
       .Name("Test2")
       .Value(Model.Y)
       .Tooltip(t => t.Enabled(true).Format("{0:n}"))
       .IncreaseButtonTitle("Plus")
       .DecreaseButtonTitle("Moins")
       .DragHandleTitle("Ajuster")
       .Min(@Convert.ToDouble(Model.X - Model.Min))
       .Max(@Convert.ToDouble(Model.X + Model.Max))
       .SmallStep(0.05)
       .LargeStep(0.2))
$("#Test").kendoSlider({
    increaseButtonTitle: "Plus",
    decreaseButtonTitle: "Moins",
    min: 0.5,
    max: 2.2,
    smallStep: 0.05,
    largeStep: 0.1
}).data("kendoSlider");

 

The only difference is the value stored in the input by Kendo().Slider() which is 1,3 instead of 1.3 : the slider for Test has its value set correctly while the slider for Test2 has not.

My _Layout has :

<script type="text/javascript">
    kendo.culture("fr-FR");
</script>

And my culture is fr-FR in my threads.

I tried the snippet you posted : Setting the value Y as a string and using Convert.ToDouble(Model.Y) : the value is set to 1,3 as well.

What can I do?

0
Stéphane
Top achievements
Rank 1
answered on 23 Mar 2016, 02:41 PM

EDIT: To clarify and simplify my problem:

I have a slider for a viewmodel's property Y typed as a decimal.

I use Kendo.SliderFor(m => m.Y) with Y being set to "1.3M" in the constructor of that viewmodel.

I expect the slider's knob to be on the value 1.3 (around the middle of it since it goes from 0.5 to 2.2)

I have the slider's knob all the way to the right

What's also surprising is the values for steps, Min and Max are set as 0.5 and 2.2 in the dom though they are decimal as well. Only the field value is somehow converted to fr-FR culture along the way and gets set as 1,3

0
Stéphane
Top achievements
Rank 1
answered on 23 Mar 2016, 03:32 PM

EDIT2 : Well... Looks like *someone* forgot to add kendo.culture and kendo.messages files for fr-FR to the solution and to the bundle.

Doing so solved the problem.

Tags
Slider
Asked by
Baldvin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Baldvin
Top achievements
Rank 1
Stéphane
Top achievements
Rank 1
Share this question
or