here is how to do it
For now it only works with a SELECT in a FORM single/mult/grid. Since the initial value of a SELECT in a single form and the multi/grid forms you will have to change the value from 0 + 3 (max values of options to be selected) in a SINGLE form to 25 + 3 in a multi/grid form. Otherwise the code wont be executed. When maximum options are selected all the other options will be deselected. Selecting more than the maximum allowed will deselect the whole list and let the user to choose again. A message is shown aswell.
I wanted to upload some screenshots but since this forum has updated this is not possible for the moment.
In OnscriptInit
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
// $("select").on('click', 'option', function() {
$("select").on('click', 'option', function() {
// CHECK VALUE OF SELECT WHEN TRIGGERED
// * SINGLE FORM USE 0 (INITIAL VALUE SELECT) + 3 (MAX OPTIONS SELECTED);
// * MULTI FORM/EDITABLE GRID/EDITABLE GRID VIEW USE 25 (INITIAL VALUE SELECT) + 3 (MAX OPTIONS SELECTED);
// alert($("select option:selected").length);
if (($("select option:selected").length == 0 + 3)){
// $(this).removeAttr("selected");
$('select option[value!=\'\']').not(':selected').prop("disabled",true);
} else if ($("select option:selected").length > 0 + 3 ) {
// USE of SWEETALERT2 SC 9.4 else add LIB
Swal.fire({
type: 'error',
title: 'Oops...',
text: 'Only 3 choices possible!',
footer: 'list will be deleted'
})
$('select option[value!=\'\']').prop("selected",false);
} else {
$('select option[value!=\'\']').prop("disabled",false);
}
});
});
</script>
<?php