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

Scheduler validate ressource

1 Answer 133 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Gora
Top achievements
Rank 1
Gora asked on 09 Aug 2016, 10:05 AM

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

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 11 Aug 2016, 07:51 AM
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
Tags
Scheduler
Asked by
Gora
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or