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

[Solved] How Do I Select All Rows Not An EditItem?

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 06 May 2013, 07:52 PM
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.

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


1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 09 May 2013, 10:27 PM
Hi Paul,

I would recommend that you use the OnValueChanging event instead. In the event handler you can check whether the newly entered value meets your requirements and if not cancel the event. Additionally you can note the user that the value entered is not valid.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or