In a Kendo Grid, I have a column that contains a date. I'm using this method for inserting my own control into the cell to edit the date:
function
dateTimeEditor(container, options)
{
console.log(
"options"
, options);
$(
'<input data-text-field="'
+ options.field +
'" '
+
'data-value-field="'
+ options.field +
'" '
+
'data-bind="value:'
+ options.field +
'" '
+
'data-format="'
+ options.format +
'" '
+
'/>'
)
.appendTo(container)
.kendoDateTimePicker(
{
format:
"MM/dd/yyyy"
,
parseFormats: [
"yyyy/MM/dd"
,
"MM/dd/yyyy"
, ],
});
}
In the column definition I have this:
{
field:
"probeDate"
,
title:
"Probe Date"
,
width: 60,
format:
"{0:MM/dd/yyyy}"
,
editor: dateTimeEditor,
attributes: { class:
"editable-cell"
},
}
So far this works great. Now I wanted to add custom validation to this control, so in the model I have a field defined like this:
type:
"date"
,
editable:
true
,
validation:
{
validateProbeDate:
function
(input)
{
if
(console != undefined) { console.log(input); }
// Validate the probeDate as well as all of the dynamic fields.
if
(input.val().trim() ===
""
|| parseDate(input.val()) ==
null
)
{
input.attr(
"data-validateProbeDate-msg"
,
"Probe Date must be a valid date value (mm/dd/yyyy or yyyy/mm/dd)."
);
return
false
;
}
// TODO: Make sure the date falls within the bounds of the probe.
// return new Date(input.val()) < probeStartDate...
return
true
;
}
}
This works as far as the validation as it doesn't allow me to leave the field unless my validation method returns true, but the error message won't show on the field and I've tried several methods to try to get it to show up. I assume the problem is in dateTimeEditor() where I'm defining the date edit control.
You can see this in action in this fiddle: Probe Data Entry
Thanks in advance!