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

Custom Validation

3 Answers 45 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Sergio
Top achievements
Rank 1
Sergio asked on 26 Apr 2017, 09:03 PM

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 !!

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 28 Apr 2017, 09:35 AM
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 (charts) and form elements.
0
dbCF
Top achievements
Rank 2
answered on 01 Aug 2018, 12:14 PM

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

0
Tsvetina
Telerik team
answered on 03 Aug 2018, 08:04 AM
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.
Tags
TreeList
Asked by
Sergio
Top achievements
Rank 1
Answers by
Stefan
Telerik team
dbCF
Top achievements
Rank 2
Tsvetina
Telerik team
Share this question
or