Use DisplayFormatAttribute with NumericTextBox

2 posts, 1 answers
  1. C.P.A.M. Van Aaken
    C.P.A.M. Van Aaken avatar
    3 posts
    Member since:
    Jan 2007

    Posted 30 Sep 2014 Link to this post

    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?

  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 02 Oct 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
Back to Top