Validation for DropDownList if ForeignKeyField is null

Hello,

I'm working on ej:dropdownlist.  I implemented dropdownlist in grid and added validation.
My requirement is when ForeignKeyField is null or nothing, I want show validation message same as when it is not selected anything in dropdown.  Can I do this for ej:dropdownlist.

I attach sample solution.  If I selected N/A in dropdownlist, I want error popup shows on the dropdownlist in the grid.

Best Regards,
Yukiko


Attachment: test_c56b8bf2.7z

3 Replies

VN Vignesh Natarajan Syncfusion Team July 27, 2018 11:35 AM UTC

Hi Yukiko, 

Thanks for using Syncfusion products. 

From your query, we understand that you want to display the validation message when value selected from dropdownlist equals “N/A”. We have achieved your requirement using Custom Validation jQuery method. 

Refer the below code example 

<ej:Grid ID="Grid1" runat="server" AllowPaging="True"  DataSourceID="test34" ClientIDMode="AutoID" DataKeyNames="memberId" >  
.                .               .               .                .               
            <ej:Column Field="HomePortCode" HeaderText=" Home Port Code" Width="190px" EditType="Dropdown" TextAlign="Left"> 
                   <ValidationRule> 
                        <ej:KeyValue Key="customRegex" Value="5" /> 
                    </ValidationRule> 
            </ej:Column> 
 
.                       .                .               .             .  
                </Command> 
            </ej:Column> 
        </Columns> 
</ej:Grid> 
<script type="text/javascript"> 
        $(function () {            
            $.validator.addMethod("customRegex", function (value, element, params) { 
                if (element.value != "N/A" && element.value != "") 
                    return true; 
                return false; 
            }, "Select a valid value"); 
        }); 
         
    </script> 
    
Refer the below screenshot for the output 

 


For your convenience we have attached the modified which can be downloaded from below link 




Refer our help documentation for your reference 


Please get back to us if you have further queries. 

Regards, 
Vignesh Natarajan 





YI Yukiko Imazu July 27, 2018 02:50 PM UTC

Hi Vignesh,


Thank you for you support.

Issue is solved.


Best Regards,

Yukiko




VN Vignesh Natarajan Syncfusion Team July 30, 2018 08:25 AM UTC

Hi Yukiko, 

Thanks for the update. 

We are happy to hear that your query has been resolved by our solution. 

Please get back to us if you have further queries. 

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon