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

Not able to validate Date field in Grid

1 Answer 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Veteran
Steve asked on 07 Oct 2019, 09:43 PM

I have a Grid with an editable DateTime field. What happens is when I type in a date, if it doesn't adhere to the Format statement, it clears the field when I hit tab. What I want is if I enter something like 01012020, I want to try and parse it in javascript and get a valid date to use. I have tried using OnBlur, but that never gets called. The onDateChange function has null for the value of that field. I think it's already cleared it out.

The grid defines the field and the editor template as,

.Columns(proposed =>
{
proposed.Bound(prop => prop.DateProposed).Editable("true").EditorTemplateName("SelectDateDD").Format("{0:MM/dd/yyyy}").Title("Date").Width(113);
}

SelectDateDD:

@(Html.Kendo().DatePickerFor(m => m).Events(e=>e.Change("onDateChange")))

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 10 Oct 2019, 09:09 AM

Hi Frank,

Thank you for the provided code snippets and explanation of the scenario you are willing to achieve.

Basically, the input of the picker remains empty because the input value has been invalid. Therefore, the internal value property of the picker remains null.

Instead of subscribing to the blur event(which might be too late on some occasions), I would suggest overriding the default validator for the row. An example of how to handle custom validation could be found in the demo below. Within the handler, you would be able to assign values accordingly, as well.

https://demos.telerik.com/aspnet-core/grid/editing-custom-validation

Let me know in case further assistance is required.

 

Best regards,
Tsvetomir
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
Grid
Asked by
Steve
Top achievements
Rank 1
Veteran
Answers by
Tsvetomir
Telerik team
Share this question
or