Custom Validation

4 posts, 0 answers
  1. Sergio
    Sergio avatar
    3 posts
    Member since:
    Apr 2017

    Posted 26 Apr 2017 Link to this post

    Hello

    I had in mind to use it with "incell" edition, is there any built in custom validation as with the grid, since I can not rely on the model validation?

    Thank you very much !!

  2. Stefan
    Admin
    Stefan avatar
    2472 posts

    Posted 28 Apr 2017 Link to this post

    Hello Sergio,

    Please have in mind that the TreeList only supports inline and popup editing:

    http://docs.telerik.com/kendo-ui/api/javascript/ui/treelist#configuration-editable.mode

    I similar approach as the for the Grid can be set using kendo.validator:

    http://demos.telerik.com/aspnet-mvc/grid/editing-custom-validation

    Regards,
    Stefan
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. dbCF
    dbCF avatar
    5 posts
    Member since:
    Mar 2015

    Posted 01 Aug 2018 in reply to Sergio Link to this post

    Is this documented that one cannot rely on the model validation? I've also tried to mark the field as Nullable(false) in the model but without success.

    Is custom validation the only way to go when using ASP.NET?

    Best regards,
       Carsten

  4. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 03 Aug 2018 Link to this post

    Hello Carsten,

    The TreeList supports model validation. The validation rules in the MVC TreeList are generated based on the data annotations in the edited model. For example, in the TreeList Editing demo, the edited model is declared like this (not visible in the online demo but you can open the demos solution locally on your computer and inspect it):
    public class EmployeeDirectoryModel
    {
        [ScaffoldColumn(false)]
        public int EmployeeId { get; set; }
     
        [Required]
        [DisplayName("First name")]
        public string FirstName { get; set; }
     
        [Required]
        [DisplayName("Last name")]
        public string LastName { get; set; }
     
        [ScaffoldColumn(false)]
        public int? ReportsTo { get; set; }
     
        public string Address { get; set; }
     
        public string City { get; set; }
     
        public string Country { get; set; }
     
        public string Phone { get; set; }
     
        [Required]
        [Range(0, 9999)]        
        [DataType("Integer")]
        public int? Extension { get; set; }
     
        public string Position { get; set; }
     
        private DateTime? birthDate;
        [DataType(DataType.Date)]
        [DisplayName("Birthday")]
        public DateTime? BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                if (value.HasValue)
                {
                    birthDate = value.Value;
                }
                else
                {
                    birthDate = null;
                }
            }
        }
     
     
        private DateTime? hireDate;
        [DataType(DataType.Date)]
        [DisplayName("Hire Date")]
        public DateTime? HireDate
        {
            get
            {
                return hireDate;
            }
            set
            {
                if (value.HasValue)
                {
                    hireDate = value.Value;
                }
                else
                {
                    hireDate = null;
                }
            }
        }

    You can try deleting the FirstName or LastName value during editing in the demo or try to apply an Ext value bigger than 9999 and you will see the validation messages show up on blur.

    Regards,
    Tsvetina
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top