For context, i work on a feature composed of a list of access rights wich exclude each others. Former database :
| A | B |
| True | False |
| False | True |
Before , if A was True B was false. And the script was disabling the checkbox relatives to the other condition. (ie : check a B relevant checkbox --> A relevant checkbox are disabled)
Now there is a new access right in database wich is allowed for both A and B :
| A | B |
| True | False |
| False | True |
| True | True |
$(function() {
var updateExpert = function() {
var A = $('.fonctionnalite-check[data-A="true"]:checked').size() > 0;
var B= $('.fonctionnalite-check[data-B="true"]:checked').size() > 0;
$('.fonctionnalite-check[data-A="true"][data-B="true"]').each(function() {
$(this).prop('disabled', true);
$('#'.concat($(this).attr('data-categorie'))).prop('disabled',false);
});
$('.fonctionnalite-check[data-A="true"][data-B="false"]').each(function() {
console.log("TF");
$(this).prop('disabled', A && !B);
$('#'.concat($(this).attr('data-categorie'))).prop('disabled', B);
});
$('.fonctionnalite-check[data-B="true"][data-A="false"]').each(function() {
console.log("FT");
$(this).prop('disabled', A && !B);
$('#'.concat($(this).attr('data-categorie'))).prop('disabled', A);
});
};
That's for the context, now the problem :
When I Check a A relevant checkbox -> B relevant checkbox are disabled , and the "TRUE - TRUE" case , is ignored ( not disdabled ) -> OK
When I Check a B relevant checkbox -> A relevant checkbox are disabled , and the "TRUE - TRUE" case , is ignored ( not disdabled ) -> OK
When I Check a A && B relevant checkbox -> all others checkbox are disabled -> KO
My opinion :
- Failing selector
- bad boolean logic , maybe i'm missing something
Thanks by advance
Aucun commentaire:
Enregistrer un commentaire