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

Setting default value in CustomEditortemplate Attendees multiselect gives Null on save

2 Answers 51 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Anamika
Top achievements
Rank 1
Anamika asked on 31 Jul 2014, 09:27 AM
Hello,

I am using CustomeditorTemplate for add/edit new Event. I have a Attendes mutiselect box and bydefault it should load the loggedin user. If i set the Default value then i can see the value selected but on save click Attendees is always null. but if i remove and add again or add another then i get the value. So somehow the Change Event is not triggered when Setting Default value.

here is view code. Charlie is set Default so it Shows selected but on save click attendees is null.
<div class="k-edit-label">
@(Html.LabelFor(model => model.Attendees))
</div>
<div data-container-for="Attendees" class="k-edit-field">
@(Html.Kendo().MultiSelectFor(model => model.Attendees)
.HtmlAttributes(new { data_bind = "value:Attendees" })
.DataTextField("Text")
.DataValueField("Value")
.Value(new[] { new {Text="Charlie",Value="3" }})
.ValuePrimitive(true)
.TagTemplate("<span class='k-scheduler-mark' style='background-color:\\#= data.Color?Color:'' \\#'></span>\\#=Text\\#")
.ItemTemplate("<span class='k-scheduler-mark' style='background-color:\\#= data.Color?Color:'' \\#'></span>\\#=Text\\#")
.BindTo(new[] {
new { Text = "Alex", Value = 1, Color = "\\#f8a398" },
new { Text = "Bob", Value = 2, Color = "\\#51a0ed" },
new { Text = "Charlie", Value = 3, Color = "\\#56ca85" }
})
)

</div>
Anamika

2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 01 Aug 2014, 03:34 PM
Hello Anamika,

The Scheduler widget creates MVVM value bindings when editor form is created. MVVM value binding listens to change event of the widget in order to update the event. On the other hand, widget will not raise change event if its value is set through value method or as a configuration option (in your case Value method).
That being said, you will need to trigger change event manually in order to notify the MVVM binding that widget value has been changed. You can do that in the dataBound event of the widget:

[C#]:

Events(e => {
    e.DataBound("data_bound");
})

[JavaScript]:
function data_bound() {
    this.trigger("change");
}

Let me know if this does not solve the issue.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Anamika
Top achievements
Rank 1
answered on 04 Aug 2014, 06:49 AM
Hello,

Thanks that solved my problem

Anamika
Tags
Scheduler
Asked by
Anamika
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Anamika
Top achievements
Rank 1
Share this question
or