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

Validation firing on fields that are nullable.

3 Answers 321 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Chrys
Top achievements
Rank 1
Chrys asked on 09 Jun 2013, 04:02 PM
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; }
    }

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 12 Jun 2013, 08:44 AM
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!
0
Chrys
Top achievements
Rank 1
answered on 14 Jun 2013, 03:01 PM
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.

0
Petur Subev
Telerik team
answered on 18 Jun 2013, 10:18 AM
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!
Tags
Validation
Asked by
Chrys
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Chrys
Top achievements
Rank 1
Share this question
or