I have a Weight column in my RadGrid, which I'm using a CustomValidationFunction, which is working fine. It disallows invalid values.
But I want blank, 0 (or below) to be set automatically to the minimum value allowed, rather than making the user put it in manually. How can I accomplish this?
Here is the column I'm validating:
<telerik:GridTemplateColumn UniqueName="Weight" HeaderText="Weight" DataField="Weight" AllowFiltering="false">
<ItemTemplate><%# Eval("Weight") %></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="WeightAmt" runat="server" />
<asp:CustomValidator runat="server" ID="WeightValidator" EnableClientScript="true" ControlToValidate="WeightAmt"
ClientValidationFunction="WeightValidator" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
And here is the validation function as it currently stands:
function WeightValidator(sender, args) {
var thisWeight = parseInt(args.Value);
if (thisWeight > maxWeight) {
sender.textContent = "Weight may not be larger than " + maxWeight;
args.IsValid = false;
return;
}
if (thisWeight < 1) {
thisWeight = minWeight;
arguments[0].parentElement.parentElement.getElementsByTagName("input")[0].textContent = minWeight.toString();
}
if (thisWeight < minWeight) {
sender.textContent = "Weight may not be smaller than " + minWeight;
args.IsValid = false;
return;
}
args.IsValid = true;
}
Debug indicates the `arguments` statement sets the value, but this isn't actually tied to anything on the page, so it gets lost. The only place I see the cell value is in a hidden `div` (`style="display: none")` and I don't see any way of changing that.
In searching for a solution, I see it is recommended to edit the `innerHTML`, but that doesn't even contain the value I'm wanting to edit.
Is there a good way for validation to correct data errors that it can instead of just calling it invalid?
Hi Michael,
The code that you provided deals with user input validation. If you want values to be modified automatically, this is not relevant. I have some questions regarding the automation:
For example, a SQL query similar to the following:
If you could provide further details about the requirements, we can better counsel you.
Kind regards,
Vasko
Progress Telerik
Thank you for your response. The urgency behind it is greatly diminished, as I have found additional issues incompatible with batch editing entirely.
But to answer your questions: