ComboBoxFor - No client validation messages

4 posts, 0 answers
  1. Brent Noble
    Brent Noble avatar
    1 posts
    Member since:
    Jul 2012

    Posted 28 Jun 2012 Link to this post

    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!!!

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 03 Jul 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Eduardo
    Eduardo avatar
    2 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2012 Link to this post

    We are having the same problem, why you don't answer for the community?
    Eduardo
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 17 Sep 2012 Link to this post

    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!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready