MultiSelect "preselect" value, but also a default value

13 posts, 0 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 12 Nov 2015 Link to this post

    I want to have a MultiSelect with a default value (the name of the current user), but I also do not want to bind the data as there are far too many users to load at once.

    How can I have both? Currently, the default value overrides the pre-select value.

     

    http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/multiselect/overview#pre-select-values-on-initial-loading​

  2. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 12 Nov 2015 in reply to Matt Link to this post

    Another issue: with pre-selected value, I am able to select one of the values which has already been preselected, thus deleting both instances of that value.

    For instance, in the example if you select Chai again by typing in Chai, it will be deleted.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 17 Nov 2015 Link to this post

    Hello Matt,

    Probably, I am missing something, but the MultiSelect widget can show selected items (pre-selected ones) without binding the widget. This is accomplished passing the whole objects as widget value: This is the same link, that you posted in your first message. Please note that the widget requires to be bound in order to operate properly. Could you elaborate a bit more on "default" value?

    With regards to the second statement, there is a known issue related to the item selection. I suppose that it is related to the depicted issue:
    Regards,
    Georgi Krustev
    Telerik
    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
  5. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 19 Nov 2015 in reply to Georgi Krustev Link to this post

    .Model(model =>
    {
        model.Id(group => group.Id);
        model.Field(group => group.Administrators)
            .DefaultValue(new List<MemberViewModel>() { new MemberViewModel() { Id=CurrentUser.Id }});
    })

     

    My MultiSelect is in a grid, I set the DefaultValue of the MultiSelect with the Model parameter (see above)

    This worked fine, until I had to set the value on the MultiSelect to prevent a huge initial lookup

    @(Html.Kendo().MultiSelectFor(model => model)
        ..snip..
        .Value(Model.ToList()))

    The value appears to be overwriting the DefaultValue, even when the value is blank

  6. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 19 Nov 2015 in reply to Matt Link to this post

    My last post was the wrong way around

    DefaultValue overrides the Value of the MultiSelect

  7. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 23 Nov 2015 Link to this post

    Hello Matt,

    Indeed, the defaultValue of the model field will override the widget's value and this is expected. Basically, the model has default values and the widgets should honor those values. In other words, model default values have higher priority than the widgets values.

    If you would like to have pre-defined values in the MultiSelect, then you will need to define a default selected objects in the model. Thus on create, the grid will create a new object using default values and will apply them to the widgets in the editor template.

    Regards,
    Georgi Krustev
    Telerik
    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
  8. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 23 Nov 2015 in reply to Georgi Krustev Link to this post

    That should probably be documented, since it goes against the meaning of the word "default"...

    Default: a preselected option adopted by a computer program or other mechanism when no alternative is specified by the user or programmer.
  9. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 23 Nov 2015 in reply to Georgi Krustev Link to this post

    How can I set the model value before it has been created if I am using a server datasource? In my view model constructor I have initialized any lists that are being used, but I am unable to populate them with known default values since the constructor must be parameter less.

    If I try to create the grid without the default value set I get this error: 

    Value cannot be null. Parameter name: source
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at ASP._Page_Views_Shared_EditorTemplates_GroupViewModel_cshtml.Execute() in GroupViewModel.cshtml:line 36 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()

    Does this mean I can't use a server datasource?
  10. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 23 Nov 2015 in reply to Matt Link to this post

    GroupViewModel.cshtml:line 36 is @(Html.Kendo().Grid<GroupViewModel>()...
  11. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 26 Nov 2015 Link to this post

    Hello Matt,

    We definitely will document the "default value" behavior better in order to avoid further confusion in our users.

    I am afraid that I cannot suggest any solution in this case, because I am not fully aware how the grid is actually configured and used in your application. Generally speaking, model default values are the ones used to setup the newly created model with predefined values. You need to use them to control the values of the empty (new) model. Please note that the Grid widget creates the new model on the client even when server datasource is used. That is why the schema.model configuration is important in all cases.

    In oder to assist you further with this issue, please send us a repro demo.

    Regards,
    Georgi Krustev
    Telerik
    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
  12. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 26 Nov 2015 in reply to Georgi Krustev Link to this post

    See attached. Had to remove the kendo lib to be under the file size limit...
  13. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 26 Nov 2015 in reply to Georgi Krustev Link to this post

    See attached, kendo lib removed to be under the file size limit
  14. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 30 Nov 2015 Link to this post

    Hello Matt,

    Thank you for the repro demo. Indeed, the widget will lose its pre-selected value when it has an initial value (options.value) and model field has a default value too. I logged the case for further investigation and fix. We will try to address the limitation in some of our next official releases.

    For now, the best solution is to leave the grid's model to take control over the UI editors:
    @(Html.Kendo().MultiSelectFor(m => m.Members)
            .DataValueField("Id")
            .DataTextField("Name")
            .Placeholder("Type user's name...")
            .Filter(FilterType.Contains)
            .AutoBind(false)
            .MinLength(3)
            .DataSource(source =>
            {
                source.ServerFiltering();
                source.Read(read =>
                {
                    read.Action("ReadMembers", "Home");
                });
            })
            .Value(new string[] {}))
        @Html.ValidationMessageFor(model => model.Members)

    Regards,
    Georgi Krustev
    Telerik
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready