Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
68 views

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?

Vasko
Telerik team
 answered on 16 Nov 2023
1 answer
150 views

Hi, I'm trying to create a dynamic rad grid (two columns) for batch edit where one column can have different control based on a condition. Basically, it should look like this once click to edit the cell.

Value 1	Dropdown
Value 2	TextBox
Value 3	DatePicker
Value 4	Checkbox
Value 5	TextBox

Can anyone share a sample code for this? 

Thank You

Doncho
Telerik team
 answered on 16 Jun 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?