Restrict MultiSelect to a single selection...

5 posts, 0 answers
  1. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 14 May 2014 Link to this post

    Is there any way to restrict a multiselect to only having one selection, and then no more can be made.  I tried playing with the changed event, and checking for the number of values, and if more than zero, disabling the control, but then it wasn't possible to remove the selection, and add a new one.

    multiChanged: function(e) {
        var values = e.sender.value();
        if(values.length > 0) {
          viewModel.set("available", false);
        }
      }


    So I switched to using the select event, checking the value for more than zero.  

    selected: function(e) {
        if(viewModel.selectedNames.length > 0) {
          e.preventDefault();
        }
      },


    This seems to work, but am more wondering if there is something built-in to the multiselect so I wouldn't have to use the events.

    Here is my semi-working sample Demo@TryKendoUI

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 15 May 2014 Link to this post

    Hi Robin,

    I am afraid that there is not built-in functionality that matches your requirements. I can see that your current solution is using the built-in events and methods and I can not see a reason not to use it.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 15 May 2014 Link to this post

    Hi Robin,

    After some further looking in the configuration properties, I stumbled upon the maxSelectedItems configuration that you might use. Here is a link to the documentation:

    http://docs.telerik.com/kendo-ui/api/web/multiselect#configuration-maxSelectedItems 

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 15 May 2014 in reply to Kiril Nikolov Link to this post

    Not sure how I missed that property. Thank you so much, this is much easier.
  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 15 May 2014 Link to this post

    Hi Robin,

    Not sure how I missed it either, but glad I found it. 

    If something else comes up, please do not hesitate to contact us.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready