Validation not working in pop up editor

2 posts, 0 answers
  1. Steven
    Steven avatar
    29 posts
    Member since:
    Jul 2012

    Posted 26 Mar 2013 Link to this post

    I have a model with the [Required] attribute applied to several properties.  When I use a pop-up editor from my grid if I Update a record, the Grid DataSource's Create and Update methods are called without any validation occurring.

    Model Example:

    public class SessionMain
    {
    [Required]
    public string Title { get; set; }

    [Display(Description = "Auction")]
    [Required]
    public long AuctionID { get; set; }

    [Display(Description = "Increment Set")]
    [Required]
    public long IncrementSetID { get; set; }

    [Display(Description = "Venue")]
    [Required]
    public long VenueID { get; set; }

    [Display(Description = "Ringman Lane")]
    [Required]
    public long RingmanLaneID { get; set; }
    }

    Grid declaration:

    @(Html.Kendo().Grid<Spectrum.Model.SessionMain>()
    .Name("sessionGrid")
    .HtmlAttributes(new { style = "height: 500px" })
    .AutoBind(true)
    .Columns(columns =>
    {
    columns.Bound(c => c.ID).Groupable(false);
    columns.Bound(c => c.Title).Groupable(false);
      columns.Bound(c => c.VenueID).Groupable(true);
    columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
    }
    )
    .Editable(editable => editable
    .Mode(GridEditMode.PopUp)
    .TemplateName("SessionPopUp")
    .Window(window => {
    window.Title("Session");
    window.Name("sessionWindow");
    window.Modal(true);
    window.Resizable();
    window.Width(960);
    }))
    .Pageable(pageable => pageable
    .Enabled(true)
    .PageSizes(new int[3] { 10, 25, 50 })
    .Refresh(true))
    .Sortable()
    .Scrollable()
    .Selectable()
    .DataSource(datasource => datasource
    .Ajax()
    .Model(model => model.Id(s => s.ID))
    .Events(events => events.Error("gridError"))
    .Create(cfg => cfg.Action("GridCreate", "Session").Data("getAuctionID"))
    .Read(cfg => cfg.Action("GridRead", "Session").Data("getAuctionID"))
    .Update(cfg => cfg.Action("GridUpdate", "Session"))
    .Destroy(cfg => cfg.Action("GridDestroy", "Session"))
    .ServerOperation(false))
    .Events(ev => ev.Change("setGridChange"))
    )

    Popup Declaration (file in \Shared\EditorTemplates named "SessionPopUp.cshtml"):

    @model Spectrum.Model.SessionMain@Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.ID)<table>
        <tr>
            <td>@Html.LabelFor(model => model.Title)</td>
            <td>
                @Html.TextBoxFor(model => model.Title, new { @class = "k-textbox" })
                @Html.ValidationMessageFor(model => model.Title)
            </td>
            <td>@Html.LabelFor(model => model.SessionType, "Session Type")</td>
            <td>
                @(Html.Kendo().DropDownListFor(model => model.SessionType)
                    .Name("sessionTypeDropDown")
                    .Items(items => {
                        items.Add().Text("Live").Value("1");
                        items.Add().Text("Internet").Value("2");
                    })
                    .OptionLabel("Select Session Type...")
                )
                @Html.ValidationMessageFor(model => model.SessionType)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.IncrementSetID, "Increment Set")</td>
            <td>
                @(Html.Kendo().DropDownListFor(model => model.IncrementSetID)
                .DataTextField("Title") //Specifies which property of the Product to be used by the combobox as a text.
                .DataValueField("ID") //Specifies which property of the Product to be used by the combobox as a value.
                .DataSource(source => source
                .Read(read => read.Action("List", "IncrementSet"))
                    )
                .OptionLabel("Select Increment Set...")
                )
                @Html.ValidationMessageFor(model => model.IncrementSetID)
            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(model => model.VenueID, "Venue")
            </td>
            <td>
                @(Html.Kendo().DropDownListFor(model => model.VenueID)
                .DataTextField("Title") //Specifies which property of the Product to be used by the combobox as a text.
                .DataValueField("ID") //Specifies which property of the Product to be used by the combobox as a value.
                .DataSource(source => source
                    .Read(read => read.Action("GetVenuesList", "Venue"))
                    )
                .OptionLabel("Select Venue...")
                )
                @Html.ValidationMessageFor(model => model.VenueID)
            </td>
        </tr>
    </table>
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 28 Mar 2013 Link to this post

    Hello Steven,

    Check the attached project - the validation is working properly on my side.

    Keep in mind validation summary is not supported within kendo Grid.

    Kind Regards,
    Petur Subev
    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