We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

dialogTemplate validationRules for dropdownList


I need add validationRules for dropdownList in grid dialogtemplate.
I found similar but for ASP.NET MVC here: https://www.syncfusion.com/forums/139118/editmode-dialogtemplate-with-ejdropdownlist-validation

<td style="text-align: left"> 
                @Html.EJ().DropDownListFor(o => o.EmployeeID, (Syncfusion.JavaScript.Models.DropDownListProperties)ViewBag.ddl).DropDownListFields(o=>o.Text("id").Value("id")).ValidationRules(v=>v.AddRule("required", true)) 

I have:

<ejs-dropdownlist width="200" id="EmployeeID" dataSource="@ViewBag.Employees" filtering="onfiltering" placeholder="Wybierz Pracownika" allowFiltering="true" filterBarPlaceholder="Wyszukaj"
                                      headerTemplate="@Html.Raw("<div class=\"header\"> Imię i Nazwisko</span></div>)")"
                                      itemTemplate="@Html.Raw("<div class=\"name\"> ${Name} ${Surname} </div>")"
                                      valueTemplate="@Html.Raw("<div class=\"name\"> ${Name} ${Surname} </div>")"
                        <e-dropdownlist-fields validationRules="@(new { required=true})" text="EmployeeID" value="EmployeeID"></e-dropdownlist-fields>

I need to validate if dropdownlist is selected from list. Default is null. I want to prevent close dialog if dropdownlist is not selected.
Flag validationRules don't work here.

In Grid when i add:

<e-grid-column validationRules="@(new { required=true})" allowEditing="false" field="EmployeeID" width="80" headerText="EmployeeID" visible="false"></e-grid-column>

don't work too. Works only for input text.

3 Replies

PS Pavithra Subramaniyam Syncfusion Team June 4, 2019 11:12 AM UTC

Hi Blazej, 
Thanks for contacting Syncfusion support. 
You have disabled the “visible” property of EmployeeID column so the form validation is not applied to that column. However you can achieve your requirement by adding the validation rule for “employeeID” column in the actionComplete event. Please refer to the below code example and documentation link for more information. 
    function actionComplete(args) { 
        if ((args.requestType === 'beginEdit' || args.requestType === 'add')) { 
            // Add Validation Rules 
            args.form.ej2_instances[0].addRules('EmployeeID', { required: true }); 
        if (args.requestType === 'beginEdit') { 
           // send ajax for edit partial 
            .  .  . 
        if (args.requestType === 'add') { 
          // send ajax for add partial 
            .  .  .  
Pavithra S. 

BL Blazej June 4, 2019 01:22 PM UTC

Great!. Thank you. It work!

MS Manivel Sellamuthu Syncfusion Team June 5, 2019 04:35 AM UTC

Hi Blazej, 
Thanks for your update. 
We are happy to hear that your problem has been resolved. 

Live Chat Icon For mobile
Up arrow icon