Validation firing on fields that are nullable.

4 posts, 0 answers
  1. Chrys
    Chrys avatar
    45 posts
    Member since:
    Feb 2013

    Posted 09 Jun 2013 Link to this post

    I have a kendo grid for user managment when I go  to edit a user fields that are nullable byte keep on saying that the fields are required if i don't select a value for them.

    Here is my view code for these and model.

    <div class="phoneNumberEntry">
                        <div class="phoneModalDropdown">@Html.DropDownListFor(model => Model.Phone1.PhoneTypeId, ViewBag.PhoneTypeList1 as SelectList, new { @style = "width: 105px" })</div>
                        <span class="phoneNumber">@Html.EditorFor(model => Model.Phone1.PhoneNumber)</span>
                        <span class="extension">@Html.EditorFor(model => Model.Phone1.PhoneExtension)</span>
                        <span class="isPrimary">Primary: <input type="checkbox" data-bind="checked: Phone1.IsPhonePrimary"/></span>
                    </div>
     
                    <div class="phoneNumberEntry">
                        <div class="phoneModalDropdown">@Html.DropDownListFor(m => m.Phone2.PhoneTypeId, ViewBag.PhoneTypeList2 as SelectList, "Select Type", new { @style = "width: 105px" })</div>
                        <span class="phoneNumber">@Html.EditorFor(model => Model.Phone2.PhoneNumber)</span>
                        <span class="extension">@Html.EditorFor(model => Model.Phone2.PhoneExtension)</span>
                        <span class="isPrimary">Primary: <input type="checkbox" data-bind="checked: Phone2.IsPhonePrimary"/></span>
                    </div>
     
                    <div class="phoneNumberEntry">
                        <div class="phoneModalDropdown">@Html.DropDownListFor(m => m.Phone3.PhoneTypeId, ViewBag.PhoneTypeList3 as SelectList, "Select Type", new { @style = "width: 105px" })</div>
                        <span class="phoneNumber">@Html.EditorFor(model => Model.Phone3.PhoneNumber)</span>
                        <span class="extension">@Html.EditorFor(model => Model.Phone3.PhoneExtension)</span>
                        <span class="isPrimary">Primary: <input type="checkbox" data-bind="checked: Phone3.IsPhonePrimary"/></span>
                    </div>
     
    public class PhoneType
        {
            public string PhoneTypeDesc
            { get; set; }
            public byte? PhoneTypeId
            { get; set; }
        }
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 12 Jun 2013 Link to this post

    Hello Chrys,

    Basically only the data-val-number attribute should be rendered which check if the value the DropDownList provided is a number, no required attribute is rendered and there should not be required validaiton.

    Check the attached project and if there is something missing modify the project and send it back.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Chrys
    Chrys avatar
    45 posts
    Member since:
    Feb 2013

    Posted 14 Jun 2013 Link to this post

    Actually after you mentioned that it seems to be the problem. The thing I noticed about yours was that the rendered html turned out like this 
    <select name="PhoneTypeId" id="PhoneTypeId" style="width: 105px;" data-bind="value:PhoneTypeId"><option value="23">T1</option><option value="">Empty</option></select>

    And myn turnes out like this.

    <select name="Phone1.PhoneTypeId" class="k-invalid" id="Phone1_PhoneTypeId" aria-invalid="true" style="width: 105px;" data-val="true" data-val-number="The field PhoneTypeId must be a number." data-bind="value:Phone1.PhoneTypeId"><option value="4">Fax</option><option value="2">Home</option><option value="3">Mobile</option><option value="1">Work</option></select>

    is there some script I need to shut off.

    Also if you notice in my project that Phone is an associated object to the model not part of the model. I'm starting to suspect thatt kendo doesn't support this very well.

  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 18 Jun 2013 Link to this post

    Hello Chrys,

    Indeed Kendo does not support editing of fields of nested objects. When it comes to editing nested objects I can suggest you to proceed the same way as in this demo:

    http://demos.kendoui.com/web/grid/editing-custom.html

    However I assume that in your case you are editing field of that nested object.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready