Setting default value in CustomEditortemplate Attendees multiselect gives Null on save

3 posts, 0 answers
  1. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 31 Jul 2014 Link to this post

    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. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3748 posts

    Posted 01 Aug 2014 Link to this post

    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!
     
  3. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 04 Aug 2014 in reply to Georgi Krustev Link to this post

    Hello,

    Thanks that solved my problem

    Anamika
Back to Top