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

RadMultiSelect doesn't seem to work with RequiredFieldValidator

6 Answers 391 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Veteran
Iron
Rob asked on 20 May 2020, 06:44 PM
I just get the following stacktrace:
An unknown error has occurred.Control '[ControlNamePlaceholder]' referenced by the ControlToValidate property of 'reqControlNamePlaceholder' cannot be validated

 

Is this by design, or is this control different than all the rest that do work with a requiredfieldvalidator?

6 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 20 May 2020, 06:52 PM
Here is an example of the code in question
<asp:RequiredFieldValidator ID=
"reqControlNamePlaceholder" ControlToValidate="Test" EnableClientScript="true" ValidationGroup="Tests" ForeColor="Red" ErrorMessage="Required" runat="server"></asp:RequiredFieldValidator>
<telerik:RadMultiSelect runat="server" DataValueField="text" Placeholder="Select Test Value..." AutoClose="false" TagMode="Single" DataTextField="text" Width="100%" ID="ControlNamePlaceholder" ></telerik:RadMultiSelect>
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 21 May 2020, 11:14 AM
Here is an example of the code in question
<asp:RequiredFieldValidator ID="reqControlNamePlaceholder" ControlToValidate="Test" EnableClientScript="true" ValidationGroup="Tests" ForeColor="Red" ErrorMessage="Required" runat="server"></asp:RequiredFieldValidator>

<telerik:RadMultiSelect runat="server" DataValueField="text" Placeholder="Select Test Value..." AutoClose="false" TagMode="Single" DataTextField="text" Width="100%" ID="ControlNamePlaceholder" ></telerik:RadMultiSelect>
0
Accepted
Peter Milchev
Telerik team
answered on 25 May 2020, 11:25 AM

Hello Rob,

I have logged the integration of the MultiSelect with the required field validator as a feature request in our Feedback portal where you can subscribe and get notified when there is any progress on it:

Meanwhile, you can use a custom validator as demonstrated below:

<telerik:RadMultiSelect ID="RadMultiSelect1" runat="server" DataTextField="text" DataValueField="value">
    <Items>
        <telerik:MultiSelectItem Text="Item 1" Value="1"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Item 2" Value="2"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Item 3" Value="3"></telerik:MultiSelectItem>
    </Items>
</telerik:RadMultiSelect>

<telerik:RadButton runat="server" ID="RadButton1" Text="Postback" AutoPostBack="true" />

<asp:CustomValidator ErrorMessage="Please select an item" ClientValidationFunction="ClientValidationFunction" runat="server" />
<script>
    function ClientValidationFunction(sender, args) {
        var multiselect = $find("<%= RadMultiSelect1.ClientID %>");

        if (multiselect.get_value().length == 0) {
            args.IsValid = false;
        }
    }
</script>

As a small token of gratitude for bringing this to our attention, I have updated your Telerik points.

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 25 May 2020, 11:56 AM
Thanks Peter. I'll try this workaround. 
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 03 Jun 2020, 01:43 PM
Yes, this workaround worked for me. Thanks!
0
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 04 Feb 2021, 12:56 AM
This solution is fine for just one control, but if you have multiple RadMultiSelect controls, you will need a more generic approach:

Here's my easy solution to be able to access the control to validate on client side.
Add the regular Custom Validator control with the options you might need.

   
<asp:CustomValidator ID="cvalShippingRegionCountries" ErrorMessage="Choose a country" ClientValidationFunction="ClientValMultiSelectCountries" runat="server" Display="Dynamic" SetFocusOnError="true" />


Then, in code behind, just add a custom attribute to store the clientID of the MultiSelect control to validate.

   
cvalShippingRegionCountries.Attributes.Add("ControlToValidateClientID", multiselectShippingRegionCountries.ClientID);


Now, in the function that deals with the validation you can access the value like this:

   
function ClientValMultiSelectCountries(sender, args) {
 
            var multiselect = $find(sender.attributes.controltovalidateclientid.nodeValue);
 
            if (multiselect.get_value().length == 0) {
                args.IsValid = false;
            }
        }


You will get the clientID inside your generic function ;)
Tags
MultiSelect
Asked by
Rob
Top achievements
Rank 1
Veteran
Iron
Answers by
Rob
Top achievements
Rank 1
Veteran
Iron
Peter Milchev
Telerik team
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or