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

[Solved] Client side validation works on the first editable row

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 10 Jun 2009, 08:15 PM

Hello

I have a custom validator attached to a column.  Here is the item_created event

  protected void radDeferredIncome_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("AdvanceVarianceComment");
                TableCell cell = (TableCell)editor.TextBoxControl.Parent;
 
                GridNumericColumnEditor proposed = (GridNumericColumnEditor)item.EditManager.GetColumnEditor("ProposedAdvanceTargetAmount");
                GridNumericColumnEditor expected = (GridNumericColumnEditor)item.EditManager.GetColumnEditor("ExpectedAdvanceTargetAmount");
 
                CustomValidator val = new CustomValidator();
                editor.TextBoxControl.ID = "AdvanceVarianceComments";
 
                val.ControlToValidate = editor.TextBoxControl.ID;
                val.ErrorMessage = "*";
                val.Attributes.Add("proposed", proposed.NumericTextBox.ClientID);
                val.Attributes.Add("expected", expected.NumericTextBox.ClientID);
                val.ClientValidationFunction = "advanceVarianceValidation";
                cell.Controls.Add(val);
            }
        }  

I am using in-grid editing. I am passing in 2 attributes that are the clientId's of the 2 textboxes i need to compare. Basically, If the difference
between the 2 textboxes is not zero and a comments textbox is blank that the row is not valid.

The javascript is below.


<

 

telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

 

 

<script type="text/javascript" language="javascript">

 

 

function advanceVarianceValidation(sender, args) {

 

 

var isValid = true;

 

 

var proposed = document.getElementById(sender.attributes["proposed"].value).value;

 

 

var expected = document.getElementById(sender.attributes["expected"].value).value;

 

alert(proposed +

',' + expected);

 

 

if ((proposed - expected) != 0) {

 

 

if (args.value == null || args.value.length == 0) {

 

isValid =

false;

 

}

}

 

args.IsValid = isValid;

}

 

</script>

 

 

</telerik:RadCodeBlock>


This works if i am editing the first row but the validation does not fire if i am editing any other.

Anyone have any ideas.



Thanks,


John

 

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 Jun 2009, 01:17 PM
Hello John,

Please verify there are no JavaScript errors, after first row is edited. Also you can check whether the correct ClientIDs are added to the CustomValidatior and it is correctly added to the cell. I will suggest you examine these online help article and demo and verify whether this discrepancy appears:
http://www.telerik.com/help/aspnet-ajax/grdvalidation.html
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/validation/defaultcs.aspx

Let me know how it goes.

Kind regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or