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

Custom Create Process and Validation Issue on nullable

3 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gaetano
Top achievements
Rank 1
Gaetano asked on 27 Mar 2014, 10:31 AM
Hi Guys,

First of all, here's my grid definition

@(Html.Kendo().Grid<DATACLASS_ATTRIBUTES_T012>()
            .Name("Grid")
            .ToolBar(commands => { commands.Create().Text("New Attribute"); })
            .Columns(columns =>
            {
                columns.ForeignKey("ATTRIBUTEID", ViewBag.Attributes).ClientTemplate("#: data.DC_ATTRIBUTES_T006 ? DC_ATTRIBUTES_T006.NAME : 'none'#").Width(270);
                columns.Command(command => { command.Edit().UpdateText("Save"); }).Width(173);
                 
            })
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable()
            .Editable(mode => mode.Mode(GridEditMode.InLine))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(5)
                .ServerOperation(false)
                .Model(model =>
                {
                    model.Id(v => v.ID);
                    model.Field(v => v.ATTRIBUTEID).DefaultValue(1);
                    model.Field(v => v.UOM_ID).DefaultValue(null);
                    model.Field(v => v.DATACLASS_ID).DefaultValue(Model.ID);
                })
                .Read(r => r.Action("GetAttributeByDataClass/" + Model.ID, "Attribute"))
                .Update(r => r.Action("UpdateDataClassAttribute", "Attribute"))
                .Create(r => r.Action("CreateDataClassAttribute", "Attribute"))
             )
        )

My validation issue is that, on create, if I try to save without selecting a value for UOM_ID, I get the "The field Measure Unit must be a number." error.
Here is the data annotation related to this field

[UIHint("MeasureUnitEditor")]
[Display(Name = "Measure Unit")]
public Nullable<int> UOM_ID;

How come that validation doesn't succeed when the dafault value for that field is null (as defined inside grid's model) and the model's field is Nullable??

My Goal here is to build a custom creation process...I'd like to set the measure unit only if the value choosen from the first field (attributeID - rendered as a combo) is of a certain type...
Is it possible?

Thanks
Fabio

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 31 Mar 2014, 07:49 AM
Hello Fabio,

I am not able to reproduce such issue. Could you please check the attached project and if I missed something modify it and send it back so I can search for a solution.


Regards,
Petur Subev
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Gaetano
Top achievements
Rank 1
answered on 02 Apr 2014, 03:42 PM
Hi Petur,
I edited your example to reproduce my case. (I'm sending you just edited files to keep the pck under 2mb)
if you try to add a new row without specifying a "role", you'll get the error...

there is a difference though...in this example I used column.BOUND instead of foreignKey.... I tried w the fk column but in that case I never had the drop down showing the -1 index...and so it was impossible to try to send that field as null..
anyway you should be able to check the issue now!

Thanks!
Fabio
0
Petur Subev
Telerik team
answered on 04 Apr 2014, 08:44 AM
Hello Fabio,

Thank you for sending the modified version. I checked it and this happens due to the fact that you are using a standard select element. Indeed the validator says the value must be a number. I logged the issue in our internal system.

As a work-around I can suggest you to use the Kendo DropDownList widget as an editor.

e.g.

@(
    Html.Kendo().DropDownListFor(m=>m).BindTo( ViewBag.Roles as SelectList).OptionLabel("Choose...")
     
)

If you wonder what the difference is and where the issue is coming from, this happens because jQuery val() method returns empty string for input elements, and null for empty select element. Kendo DropDownList uses a hidden input which makes the difference between using a select element.

I am sorry for any inconvenience caused.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Gaetano
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Gaetano
Top achievements
Rank 1
Share this question
or