combobox validation

Hello,
Could you please provide some example how to implement validation in the combobox ?
Thanks,

3 Replies

KR Keerthana Rajendran Syncfusion Team February 7, 2018 08:48 AM UTC

Hi Yuri,   
   
Thank you for contacting Syncfusion Support.   
   
Currently, we don’t have inbuilt support for validation of ComboBox in source level. But you can validate ComboBox input using jquery validation by adding name attribute through htmlAttributes property of Combobox. Refer to the below given code   
   
@{   
    IDictionary<stringobject> controlname = new Dictionary<stringobject>();   
    controlname.Add("name""select");   
   
}   
<form id="form1">   
    <div class="frame">   
        <div class="row">   
            <div class="col-xs-8 col-sm-4">   
                <span class="txt">Select Country</span>   
                <ej-combo-box id="countryList" datasource="(IEnumerable<Countries>)ViewBag.datasource1" html-attributes="controlname" auto-fill="true"select="onselect">   
                    <e-combo-box-fields text="text" />   
                </ej-combo-box>   
                <label class="errormessage"></label>   
            </div>   
        </div>   
        <button type="submit" id="valid" onclick="validate()"> Validate</button>   
    </div>   
    <script type="text/javascript">   
        function validate() {   
            var rules = {};   
            $("form[id$=form1] input[name$=select]").each(function () {   
                rules[this.name] = "required";   
            });   
            $('form[id$="form1"]').validate({   
                rules: rules,   
                errorPlacement: function (error, element) {   
                    $(error).insertAfter($(".errormessage"));   
                }   
            });   
        }   
        function onselect(args) {   
            if (args.value != "") {   
                $("label.error").css("display""none")  //hide error message when value is selected.   
            }   
        }   
   
    </script>   
       
</form>   
   
   
We have attached sample for your reference which can be downloaded from the following link   
   
   
Regards,   
Keerthana.  
 



YG Yuri Gusko February 7, 2018 02:50 PM UTC

Hi Keerthana,
Thank you for quick response. 
I tried to run the example. 
When I press <Validate> button, I assume  'required' message should appear  in case I select nothing in the combobox.
Unfortunately it not happens. 
Please advise.
Thanks,


PO Prince Oliver Syncfusion Team February 8, 2018 05:28 AM UTC

Hi Yuri,      
  
Thank you for your update.   
  
We have checked the attached sample, we can validate the ComboBox upon pressing the “<validate>” button. We have attached a video demonstrating the same, kindly refer to the following link: http://www.syncfusion.com/downloads/support/forum/135795/ze/CBvalidation-274453804 

If you still facing any issue, kindly provide us additional information on the issue, perhaps a video demonstration or sample. Maybe you can modify the sample attached to the previous update to exhibit the issue and send us for further investigation.   
  
Regards,   
Prince   


Loader.
Up arrow icon