So we have a group of checkboxes. There is a max limit of 3 that can be selected which is great. This is for a product designer I am working on so I can make custom orders for people. I have noticed when testing that people get frustrated when they want to go and click another checkbox but since the three have been picked they have to go back and uncheck a checkbox before making another selection. Its not the biggest deal but I would like for that flow to not be broken.
Here is a quick example of some checkboxes and a jquery max limit.
$('input[type=checkbox]').change(function(e) {
if ($('input[type=checkbox]:checked').length > 3) {
$(this).prop('checked', false)
alert("allowed only 3");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="pricing-levels-3">
<p><strong>(Select 3 Checkboxes)</strong></p>
<input class="single-checkbox" type="checkbox">1<br>
<input class="single-checkbox" type="checkbox">2<br>
<input class="single-checkbox" type="checkbox">3<br>
<input class="single-checkbox" type="checkbox">4<br>
<input class="single-checkbox" type="checkbox">5<br>
</div>
Would I need to make an array that logs each chosen checkbox so when we go over our max, say over three into the fourth choice it unchecks the checkbox at the bottom of the array and then unloads it before loading the next one in?
In some other words, I sort of want this to work like a radio button but with the advantages of checkboxes where the user can check and uncheck multiple options but if they go over it just unloads one of their previous choices.
Any suggestions or examples would be greatly appreciated. I have only been able to find examples of limiting the amount of checkboxes that can be selected. Nothing for this particular case.
2
Answers
Let’s play around some examples before deciding on the pros/cons and ultimately what’s best for a specific use case, UI/UX.
Just, don’t show alert popups and stuff: the alerts are the interaction-flow disrupting factor, not the checkboxes alone.
Three different approaches ahead:
1. Disable checkboxes
The simplest and perhaps the best. The user has to consciously and deliberately uncheck a previous one – instead of our code automagically doing programmatic stuff behind the user’s back. The
disabled
attribute is a well known UI/UX visual state.Imagine you’re ordering extras (sauces, spices, etc) and you can check three for the price. If the notice explicitly states that one can order up to three extras, logically one will uncheck a less desired product (to make place) for the more desired one. Such UI behavior can be picked up pretty quickly by the majority of users.
Pros:
Cons:
2. Uncheck last checked
Another way is to remember the last checkbox. When the
max
is reached – uncheck that last element. In this case the first two remain unchanged during that processPros:
Cons:
3. Snake unchecking
FILO-Max. Like in a snake game, when
max
is reached, the oldest one is removed and the new one is appended to the Array.Pros:
Cons:
Have you heard about „Utopia“ by Thomas Morus?
Well, greying out is „Dystopia“.
☺️
In comes Cybernetics.
To keep the Entropy á la
Claude Shannon down.
Group the options 3 times and use 3 radio buttons☺️.