Scheduler validate ressource

2 posts, 0 answers
  1. Gora
    Gora avatar
    5 posts
    Member since:
    Dec 2011

    Posted 09 Aug Link to this post

    Hi, I would like to validate ressource in a scheler

            @(Html.Kendo().Scheduler<SchedulerCustomViewDemo.Models.MeetingViewModel>()
        .Name("scheduler")
        .Date(new DateTime(2016, 6, 13))
        .StartTime(new DateTime(2016, 6, 13, 7, 00, 00))
        .Height(600)
        .Views(views =>
        {
            views.DayView();
            views.WeekView(weekView => weekView.Selected(true));
            views.MonthView();
            views.AgendaView();
            views.CustomView("kendo.ui.ToDoView", view => view.Title("To Do").Selected(true));
        })
        .Timezone("Etc/UTC")
        .Resources(resource =>
        {
            resource.Add(m => m.RoomID)
                .Title("Room")
                .DataTextField("Text")
                .DataValueField("Value")
                .DataColorField("Color")

                .BindTo(new[] {
                        new { Text = "Meeting Room 101", Value = 1, Color = "#6eb3fa" },
                        new { Text = "Meeting Room 201", Value = 2, Color = "#f58a8a" }
               });
            resource.Add(m => m.Attendees)
                .Title("Attendees")
                .Multiple(false)
                .DataTextField("Text")
                .DataValueField("Value")
                .DataColorField("Color")
                .BindTo(new[] {
                        new { Text = "Alex", Value = 1, Color = "#f8a398" },
                        new { Text = "Bob", Value = 2, Color = "#51a0ed" },
                        new { Text = "Charlie", Value = 3, Color = "#56ca85" }
               });
        })
        .DataSource(d => d
            .Model(m =>
            {
                m.Id(f => f.MeetingID);
                m.Field(f => f.Title).DefaultValue("No title");
                m.RecurrenceId(f => f.RecurrenceID);
            })
            .Events(e => e.Error("error_handler"))
            .Read("Meetings_Read", "Home")
            .Create("Meetings_Create", "Home")
            .Destroy("Meetings_Destroy", "Home")
            .Update("Meetings_Update", "Home")
        )
            )

    So I would like to valide the Attendee  Field so as to make it required but it is not possible to apply .HtmlAttribute to .Ressource :

    (HtmlAttributes(new { required = "required", data_required_msg = "Select start time", style = "width: 220px" }))

           resource.Add(m => m.Attendees)
                .Title("Attendee")
                .Multiple(false)
                .DataTextField("Text")
                .DataValueField("Value")
                .DataColorField("Color")
                .BindTo(new[] {
                        new { Text = "Alex", Value = 1, Color = "#f8a398" },
                        new { Text = "Bob", Value = 2, Color = "#51a0ed" },
                        new { Text = "Charlie", Value = 3, Color = "#56ca85" }
               });

    Regards
  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    282 posts

    Posted 11 Aug Link to this post

    Hello Gora,

    You could do that validation by using the client-side API of the Scheduler, similarly as in this Demo. In particular, you could use the save event of the widget and modify its event handler in the following way:
    function scheduler_save(e) {
        var attendeesmultiSelect = $('.k-multiselect')
        var selectedAttendees = attendeesmultiSelect.find('option[selected="selected"]');
        if (selectedAttendees.length == 0) {
            alert("There is no selected attendee for this event.");
            e.preventDefault();
        }
    }

    Regards,
    Veselin Tsvetanov
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top