Hi,
Could you please anyone advise me how can i bind model class data annotation attributes using Kendo MVVM?
I have defined the Employee model class as below,
public class EmployeeModel
{
public int EmployeeId { get; set; }
[Display(Name = "Employee Name")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "The employee name should not be empty")]
[StringLength(50, ErrorMessage = "The employee name should be less than 50 characters length")]
public string Name { get; set; }
public bool IsActive { get; set; }
}
and i have bound this model class into view page using observable object binding. I can use HTML5 attributes for validation and validate using the below Kendo validator code, EmployeeDetails - observable object.
<input type="hidden" id="employeeId" data-bind="value : EmployeeDetails.EmployeeId"/>
Name<br />
<input data-bind="value: EmployeeDetails.Name" type="text" id="Name" name="Name" class="k-textbox"
placeholder="Employee name" required validationMessage="Please enter employee {0}" />
<div></div>
<span class="k-invalid-msg" data-for="Name"></span>
<input type="checkbox" data-bind="checked: EmployeeDetails.IsActive" id="Status" />
var validator = $("#EmployeeDetailsView").kendoValidator().data("kendoValidator");
if (!validator.validate()) {
$("#Name").focus();
return false;
}
Now, how can i achieve the same validation by binding the model attributes directly to input fields with HTML5 validation attributes mentioned as above?
At the same time i have to use observable object binding for elements.
Cheers,
Mahesh
Could you please anyone advise me how can i bind model class data annotation attributes using Kendo MVVM?
I have defined the Employee model class as below,
public class EmployeeModel
{
public int EmployeeId { get; set; }
[Display(Name = "Employee Name")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "The employee name should not be empty")]
[StringLength(50, ErrorMessage = "The employee name should be less than 50 characters length")]
public string Name { get; set; }
public bool IsActive { get; set; }
}
and i have bound this model class into view page using observable object binding. I can use HTML5 attributes for validation and validate using the below Kendo validator code, EmployeeDetails - observable object.
<input type="hidden" id="employeeId" data-bind="value : EmployeeDetails.EmployeeId"/>
Name<br />
<input data-bind="value: EmployeeDetails.Name" type="text" id="Name" name="Name" class="k-textbox"
placeholder="Employee name" required validationMessage="Please enter employee {0}" />
<div></div>
<span class="k-invalid-msg" data-for="Name"></span>
<input type="checkbox" data-bind="checked: EmployeeDetails.IsActive" id="Status" />
var validator = $("#EmployeeDetailsView").kendoValidator().data("kendoValidator");
if (!validator.validate()) {
$("#Name").focus();
return false;
}
Now, how can i achieve the same validation by binding the model attributes directly to input fields with HTML5 validation attributes mentioned as above?
At the same time i have to use observable object binding for elements.
Cheers,
Mahesh