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

Use DisplayFormatAttribute with NumericTextBox

1 Answer 258 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
C.P.A.M. Van Aaken
Top achievements
Rank 1
C.P.A.M. Van Aaken asked on 30 Sep 2014, 11:50 AM
I try to  use the NumericTextBox in combination with data annotations in MVC 5.
Kendo UI v2014.2.716
Windows 7 64 bit
Internet Explorer 10.0.9200.17089
jQuery 1.9.0

I have a class with a DisplayFormat attribute on a property:

public class EnkelOppervlakteRow
{
    public int FosfaattoestandId { get; set; }
    public string Omschrijving { get; set; }
     
    [DisplayFormat(DataFormatString="{0:n3}", ApplyFormatInEditMode=true)]
    public decimal Oppervlakte { get; set; }
 
    public int? Id { get; set; }
}
   
In the view, I generate a NumericTextBox for that property:

@(Html.Kendo().NumericTextBoxFor(mdl => mdl.Oppervlakte))

Whtat I would like, is that the NumericTextBox behaved as if I wrote this:

@(Html.Kendo().NumericTextBoxFor(mdl => mdl.Oppervlakte)
    .Format("N3")
)

Writing .Format("N3") on every line where I use said property is undesirable. I would like to manage the formatting using (custom) data annotations.
If I use @Html.EditorFor, then the values in the generated textbox are formatted the way I like.

How can I achieve this with the Kendo NumericTextBox?

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 02 Oct 2014, 11:12 AM
Hi,

The NumericTextBox infers only the validator attributes (GetValidators() method is used) applied to the Model field. Currently, DisplayFormat is not supported and you will need to use the widget Format method to set a specific value format.
After further consideration we decoded tp add a support for DataFormatString in the next official release of Kendo UI scheduled for the mid of next week. You can downloaded it once it is out and give it a try.

Best regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
NumericTextBox
Asked by
C.P.A.M. Van Aaken
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or