-
Notifications
You must be signed in to change notification settings - Fork 80
Added new kb article multiselect-limit-selection #2543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Tsvetomir-Hr
merged 2 commits into
master
from
new-kb-multiselect-limit-selection-c8fda6ffa4544544bee101b95debb591
Nov 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| title: Restrict the Number of Selected Items in the MultiSelect | ||
| description: Learn how to restrict the number of selectable items in the Telerik Blazor MultiSelect component. | ||
| type: how-to | ||
| page_title: How to Restrict the Number of Selected Items in MultiSelect for Blazor | ||
| slug: multiselect-kb-limit-selection | ||
| tags: multiselect, blazor, selection limit | ||
| res_type: kb | ||
| ticketid: 1670731 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>MultiSelect for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| When using the [MultiSelect]({%slug multiselect-overview%}) component, it might be necessary to limit the number of items a user can select. For example, restricting selection to a maximum of three items. This KB article also answers the following questions: | ||
| - How to set a selection limit on MultiSelect in Blazor? | ||
| - How to prevent additional selections in MultiSelect after reaching a defined limit? | ||
| - How to notify users they've reached the maximum number of selectable items in MultiSelect? | ||
|
|
||
| ## Solution | ||
|
|
||
| To restrict the number of selectable items in a MultiSelect component, use one-way binding with the `Value` parameter and the `ValueChanged`({%slug multiselect-events%}#valuechanged) event. This approach allows you to manually update the selected items collection and enforce a maximum selection limit. | ||
|
|
||
| Below is a demonstration of how to implement a selection limit. This example restricts the user to a maximum of three selections and informs them when they have reached this limit. | ||
|
|
||
| ````RAZOR | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @if (MultiValues.Count == 3) | ||
| { | ||
| <p style="color:red;">You've reached the maximum selected count</p> | ||
| } | ||
|
|
||
| <TelerikMultiSelect Data="@MultiData" | ||
| Value="@MultiValues" | ||
| ValueChanged="@( (List<string> newValues) => OnMultiValueChanged(newValues) )"> | ||
| </TelerikMultiSelect> | ||
|
|
||
| @code { | ||
| private List<string> MultiData { get; set; } = new List<string> { | ||
| "Manager", "Developer", "QA", "Technical Writer", "Support Engineer" | ||
| }; | ||
|
|
||
| private List<string> MultiValues { get; set; } = new List<string>() { "Developer" }; | ||
|
|
||
| private void OnMultiValueChanged(List<string> newValues) | ||
| { | ||
| if (newValues.Count <= 3) | ||
| { | ||
| MultiValues = newValues; | ||
| } | ||
| } | ||
| } | ||
| ```` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [MultiSelect Overview]({%slug multiselect-overview%}) | ||
| - [MultiSelect Events]({%slug multiselect-events%}) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.