Hello,
I'm trying to implement client-side validation on the RadTextBox within an EditForm (EditFormType="Template") on a RadGrid. The scenario is one where I need to validate that the value being entered does not result in the total value for that same column to exceed a value.
For example, the RadGrid contains rows that hold an "Hours" column. When I insert or edit a new row, I want to validate that the newly entered Hours value is not going cause the total for the Hours, for the entire grid, to exceed 24 hours.
I need to do this on the client side as I need to force the validation to occur on the blur event of the text box being used in the edit form.
E.g.
I have no problem getting at the hours for the dataitems in the grid...
My problem now is determining what the hours are for the data item currently being edited, so that I can subtract that from the total hours, and then evaluate if adding the entered hours to that total will exceed 24.
Any help is appreciated.
I'm trying to implement client-side validation on the RadTextBox within an EditForm (EditFormType="Template") on a RadGrid. The scenario is one where I need to validate that the value being entered does not result in the total value for that same column to exceed a value.
For example, the RadGrid contains rows that hold an "Hours" column. When I insert or edit a new row, I want to validate that the newly entered Hours value is not going cause the total for the Hours, for the entire grid, to exceed 24 hours.
I need to do this on the client side as I need to force the validation to occur on the blur event of the text box being used in the edit form.
E.g.
<EditFormSettings EditFormType="Template"> <FormStyle Width="100%"></FormStyle> <FormTemplate> <table border="0" style="width:100%;" > <tr> <td> <span style="color: Red">*</span> <asp:Label ID="lblHoursLabel" runat="server" Text="Hours:"></asp:Label> </td> <td> <telerik:RadTextBox runat="server" ID="rtbHours" Text='<%#DataBinder.Eval(Container, "DataItem.RegularHours")%>' Width="100px" ClientEvents-OnBlur="validateEnteredHours"></telerik:RadTextBox> </td> </tr> </table> </FormTemplate> </EditFormSettings>I have no problem getting at the hours for the dataitems in the grid...
function validateEnteredHours(sender, args) { var id = sender.get_id(); var radInput = $telerik.findControl(document.forms[0], id); var hoursValue = radInput.get_value(); if (hoursValue == null) alert("An Hours Value is Required") else { var grid = $find("<%=radGridTimesheetDetails.ClientID%>"); var totalHours = 0; if (grid) { var masterTable = grid.get_masterTableView(); var Rows = masterTable.get_dataItems(); for (var i = 0; i < Rows.length; i++) { var row = Rows[i]; var isInEditMode = row.get_isInEditMode(); if (isInEditMode = false); { var hoursCell = masterTable.getCellByColumnUniqueName(row, "Hours"); var hours = parseFloat(hoursCell.innerHTML); totalHours = totalHours + hours; } } } } }My problem now is determining what the hours are for the data item currently being edited, so that I can subtract that from the total hours, and then evaluate if adding the entered hours to that total will exceed 24.
Any help is appreciated.