diff --git a/style.css b/style.css index 2bb0047..66add48 100644 --- a/style.css +++ b/style.css @@ -32,11 +32,12 @@ table input { table td.table-primary input, table td.table-active input, table.table-success input, +td.table-danger input:disabled, table input:not([disabled]) { background: transparent !important; } -table input[disabled] { +table input:disabled { background-position: center !important; } diff --git a/sudoku.js b/sudoku.js index e392768..1a8115d 100755 --- a/sudoku.js +++ b/sudoku.js @@ -178,18 +178,14 @@ function checkBox(box) { checkCandidates(box.andNeighbourhood) if (box.value) { - for (let [areaName, neighbours] of Object.entries({ + for (let [areaName, area] of Object.entries({ région: regions[box.regionId], ligne: rows[box.rowId], colonne: columns[box.columnId], })) - for (neighbour of neighbours) - if (box != neighbour && box.value == neighbour.value) { - for (neighbour of [box, neighbour]) { - neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`) - neighbour.classList.add("is-invalid") - } - } + for (neighbour of area) + if (box != neighbour) + showDuplicates(areaName, box, neighbour) } checkSuccess() @@ -204,14 +200,7 @@ function checkBoxes() { colonne: columns, })) for (area of areas) - area.sort((box, neighbour) => { - if (box.value && box.value == neighbour.value) { - for (neighbour of [box, neighbour]) { - neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`) - neighbour.classList.add("is-invalid") - } - } - }) + area.filter(box => box.value).sort(showDuplicates.bind(null, areaName)) checkSuccess() } @@ -220,6 +209,7 @@ function checkCandidates(area) { area.forEach(box => { box.setCustomValidity("") box.classList.remove("is-invalid") + box.parentElement.classList.remove("table-danger") searchCandidatesOf(box) if (box.candidates.size == 0) { box.setCustomValidity("Aucun chiffre possible !") @@ -228,6 +218,16 @@ function checkCandidates(area) { }) } +function showDuplicates(areaName, box, neighbour) { + if(box.value == neighbour.value) { + area.forEach(neighbour => neighbour.parentElement.classList.add("table-danger")) + for (neighbour of [box, neighbour]) { + neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`) + neighbour.classList.add("is-invalid") + } + } +} + function checkSuccess() { if (sudokuForm.checkValidity()) { // Correct grid if (boxes.filter(box => box.value == "").length == 0) {