I have 5 roles with radio button. So if role A,B selected user, it selects all values but if we check C,D, it allows to select them many values as they want but if user selects F, the user is allowed to select one value at a time but my code is not working. I can get as far as the A.B user but when user selects F, it is freezing the checkbox and I can't reset it so if user selects C,D, their select box would be frozen as well regardless of if else statement. What am I doing wrong?
$(document).ready(function () {
$('.checks').change(
function () {
var radioButton = $('.checks:checked').val();
if (radioButton == "A" || radioButton == "B") {
$('#input-user-market').multiselect('refresh', false);
$('#input-user-market').multiselect('selectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
}
else if (radioButton == "C" || radioButton == "D") {
$('#input-user-market').multiselect('selectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
$('#input-user-market').multiselect('deselectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
}
else {
$('#input-user-market').multiselect('selectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
$('#input-user-market').multiselect('deselectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
jQuery("#input-user-market").on("change", function () {
var selectedOptions = $('#input-user-market option:selected');
if (selectedOptions.length >= 1) {
// Disable all other checkboxes.
var nonSelectedOptions = $('#input-user-market option').filter(function () {
return !$(this).is(':selected');
});
var dropdown = $('#input-user-market').siblings('.multiselect-container');
nonSelectedOptions.each(function () {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');
});
}
else if (selectedOptions.length <= 100) {
var SelectedOptions = $('#input-user-market option').filter(function () {
console.log("1 select")
return $(this).is(':selected');
});
var dropdown = $('#input-user-market').siblings('.multiselect-container');
SelectedOptions.each(function () {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');
});
}
else {
// Enable all checkboxes.
var dropdown = $('#input-user-market').siblings('.multiselect-container');
$('#input-user-market option').each(function () {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', false);
input.parent('li').addClass('disabled');
});
}
});
}
}
)
});
Aucun commentaire:
Enregistrer un commentaire