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

ComboBoxFor - No client validation messages

3 Answers 425 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Brent Noble
Top achievements
Rank 1
Brent Noble asked on 29 Jun 2012, 03:29 AM

Hey There I have the following code which looks ok to me (but i'm new to MVC), when I tab out of the combobox or submit the form no validation messages are displayed. After submitting to controller, the modelstate.Valid is True.

VIEW
<div class="field-label">
    @Html.LabelFor(model => model.Name.TitleID)
 </div>
 <div class="feild-Entry">
     @(Html.Kendo().ComboBoxFor(model => model.Name.TitleID)
         .DataTextField("Description")
         .DataValueField("ID")
         .BindTo(Model.Titles)
      )
      @Html.ValidationMessageFor(model => model.Name.TitleID)
</div>

MODEL - Title Propery in Name Object
[Range(1, 5000) ]
[RequiredAttribute]
public int TitleID { get; set; }

 
HTML Output
 <!-- Title-->   
        <div class="field-label">
            <label for="Name_TitleID">TitleID</label>
        </div>
        <div class="feild-Entry">
            <input data-val="true" data-val-number="The field TitleID must be a number." data-val-range="The field TitleID must be between 1 and 5000." data-val-range-max="5000" data-val-range-min="1" data-val-required="The TitleID field is required." id="Name_TitleID" name="Name.TitleID" type="text" value="0" /><script>
 jQuery(function(){jQuery("#Name_TitleID").kendoComboBox({dataSource:[{"ID":0,"Code":null,"Description":"Not Selected"},{"ID":20,"Code":"","Description":"Captain"},{"ID":9,"Code":"","Description":"Dr"},{"ID":21,"Code":"","Description":"Judge"},{"ID":15,"Code":"","Description":"Miss"},{"ID":2,"Code":"","Description":"Mr"},{"ID":6,"Code":"","Description":"Mrs"},{"ID":19,"Code":"","Description":"Ms"},{"ID":23,"Code":"","Description":"President"},{"ID":27,"Code":"","Description":"Professor"},{"ID":22,"Code":"","Description":"Reverend"},{"ID":16,"Code":"","Description":"Sir"}],dataTextField:"Description",dataValueField:"ID"});});
</script>
            <span class="field-validation-valid" data-valmsg-for="Name.TitleID" data-valmsg-replace="true"></span>
        </div>

 
But no client side validation is displayed for the combo box, other text based input boxes show their validation i.e required etc...

Please Help, Im not sure whats going on here!!!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Jul 2012, 01:07 PM
Hello Brent,

We have replied to your question in the support ticket you have opened. For convenience and in order to avoid duplication, lets continue our communication there.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Eduardo
Top achievements
Rank 1
answered on 12 Sep 2012, 06:17 PM
We are having the same problem, why you don't answer for the community?
Eduardo
0
Daniel
Telerik team
answered on 17 Sep 2012, 02:09 PM
Hello Eduardo,

I pasted the reply to the support ticket below.

The jQuery validate framework validates only the input element which is bound to a specific Model property. In the case with the ComboBox, this input is hidden. As you probably know the ComboBox component has two input elements. One for the selected value and one for the selected text. Only the selected value has any value for the validation, because it will be used to bind the property of the Model.
In order to validate the ComboBox component using jQuery validate you will need: 

  1. To clear the ignore selectors (ver. 1.9+). Check the _Layout.cshtml
  2. Handle to focusout event of the second input element. Thus you can validate the value of the hidden one.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Brent Noble
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Eduardo
Top achievements
Rank 1
Share this question
or