EditMode.DialogTemplate with ejDropDownList validation

Hi,

We are making use of the dialog edit mode on the grid. One of the fields has the 'required' validation rule on it:

                        col.Field(c => c.FieldName)
                            .ValidationRules(v => v.AddRule("required", true))
                            .Add();

We would like to make use of the ejDropDownList for this field on the dialog. So we create the drop down during the 'beginedit' or 'add' requestType of the completion method by using the JS api: 

$("#FieldName").ejDropDownList();

However, when we do this, the validation that was associated with the field via the grid is lost.

Is there a way to somehow duplicate the validation rules onto the ejDropDownList from the original html element so that when we change the fields value the validation will fire?

4 Replies

VN Vignesh Natarajan Syncfusion Team August 8, 2018 03:48 AM UTC

Hi Malcolm, 

Thanks for using Syncfusion products 

From your query, we understand that you need to render ejDropdownList while editing a record. By default we have given support for different edit type like dropdownlist, numerictextbox etc.  

So kindly refer code example 

col.Field("ShipCountry").HeaderText("Ship Country").EditType(EditingType.Dropdown).ValidationRules(v => v.AddRule("required", true)).Width(85).Add(); 

Refer the below help documentation for your reference 


If you are still facing the issue please get back to us with more details.   

Regards, 
Vignesh Natarajan  




MV Malcolm van Staden August 8, 2018 05:53 AM UTC

Thank you, that information was useful.

Is it also possible to be able to wire up JS events on that control (like the change event) via the asp.net code or should that rather be done via the JS code itself on beginedit?


MV Malcolm van Staden August 8, 2018 07:36 AM UTC

This gave more information concerning what we wanted to achieve:
https://www.syncfusion.com/kb/7746/how-render-ejcontrols-in-the-edit-form-template-of-the-mvc-grid

I was wrong, we are using EditMode.DialogTemplate, not Dialog


PK Prasanna Kumar Viswanathan Syncfusion Team August 9, 2018 11:56 AM UTC

Hi Malcolm, 

Thanks of the update. 

Query1: “Is it also possible to be able to wire up JS events on that control (like the change event) via the asp.net code or should that rather be done via the JS code itself on beginedit” 

In previous update you have mentioned that you are going to achieved your requirement with knowledgeBase documentation(https://www.syncfusion.com/kb/7746/how-render-ejcontrols-in-the-edit-form-template-of-the-mvc-grid ). In that documentation we have placed the MVC controls within the editForm using the partial view concept of the MVC.  

Based on the KB documentation you can able to wire up the JS events on that control via the asp.net code.  
 
Refer the below code example 

<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)).ClientSideEvents(e=>e.Change("change").Select("select")) 
            </td> 
   
Query2: “I was wrong, we are using EditMode.DialogTemplate, not Dialog” 

As per you suggestion we have prepared a sample similar to knowledge base document and we are able to reproduce the reported issue (validation is not set to dropdown list). We suggest you achieve your requirement by defining the ValidationRules to dropdown element while rendering in the partial view.  

Refer the below code example 

<div id="template"> 
    <b>Order Details</b> 
    <table cellspacing="10"> 
        <tr> 
            <td style="text-align: right;"> 
                Order ID 
            <td style="text-align: left"> 
                @Html.EJ().AutocompleteFor(o => o.OrderID).CssClass("e-field valid") 
            </td> 
            <td style="text-align: right;"> 
                Customer ID 
            </td> 
            <td style="text-align: left"> 
                @Html.EJ().AutocompleteFor(o => o.CustomerID).CssClass("e-field valid") 
            </td> 
        </tr> 
        <tr> 
            <td style="text-align: right;"> 
                Freight 
            </td> 
            <td style="text-align: left"> 
                @Html.EJ().NumericTextBoxFor(o => o.Freight) 
            </td> 
            <td style="text-align: right;"> 
                Employee ID 
            </td> 
            <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)) 
            </td> 
        </tr> 
        <tr> 
            <td style="text-align: right;"> 
                Order Date 
            </td> 
            <td style="text-align: left"> 
                @Html.EJ().DatePickerFor(o => o.OrderDate).CssClass("e-field") 
            </td> 
        </tr> 
    </table> 
</div> 
   
Refer the screenshot for the output 

 


For your convenience we have prepared a sample which can downloaded from below link 


Refer the help documentation for your reference 


Regards, 
Prasanna Kumar N.S.V. 

 


Loader.
Up arrow icon