Custom Create Process and Validation Issue on nullable

4 posts, 0 answers
  1. Gaetano
    Gaetano avatar
    71 posts
    Member since:
    May 2012

    Posted 27 Mar 2014 Link to this post

    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
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 31 Mar 2014 Link to this post

    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.

     
  3. Gaetano
    Gaetano avatar
    71 posts
    Member since:
    May 2012

    Posted 02 Apr 2014 in reply to Petur Subev Link to this post

    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
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 04 Apr 2014 Link to this post

    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.

     
Back to Top