Removed invalid class when valid
This commit is contained in:
		
							parent
							
								
									ab8b28feba
								
							
						
					
					
						commit
						7ebcbcff41
					
				@ -310,6 +310,28 @@ class SudokuHost extends HTMLElement {
 | 
			
		||||
	constructor() {
 | 
			
		||||
		super()
 | 
			
		||||
 | 
			
		||||
		this.#generateKeyProcessors()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	syncCellsToSudoku() {
 | 
			
		||||
		const puzzleGrid = this.#activePuzzle.grid
 | 
			
		||||
		const baseGrid = this.#activePuzzle.baseState
 | 
			
		||||
		for (let i = 0; i < SUDOKU_GRID_SIZE; i++) {
 | 
			
		||||
			this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? ""
 | 
			
		||||
 | 
			
		||||
			if (baseGrid[i] != null) {
 | 
			
		||||
				this.#cellGrid[i].classList.add("initial")
 | 
			
		||||
			} else if (puzzleGrid[i] != null) {
 | 
			
		||||
				if (this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) {
 | 
			
		||||
					this.#cellGrid[i].classList.remove("invalid")
 | 
			
		||||
				} else {
 | 
			
		||||
					this.#cellGrid[i].classList.add("invalid")
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	#generateKeyProcessors() {
 | 
			
		||||
		const cellValueProcessor = (event) => {
 | 
			
		||||
			if (this.#selectedCells.size === 0) return
 | 
			
		||||
 | 
			
		||||
@ -379,22 +401,6 @@ class SudokuHost extends HTMLElement {
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	syncCellsToSudoku() {
 | 
			
		||||
		const puzzleGrid = this.#activePuzzle.grid
 | 
			
		||||
		const baseGrid = this.#activePuzzle.baseState
 | 
			
		||||
		for (let i = 0; i < SUDOKU_GRID_SIZE; i++) {
 | 
			
		||||
			this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? ""
 | 
			
		||||
 | 
			
		||||
			if (baseGrid[i] != null) {
 | 
			
		||||
				this.#cellGrid[i].classList.add("initial")
 | 
			
		||||
			} else if (puzzleGrid[i] != null) {
 | 
			
		||||
				if (!this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) {
 | 
			
		||||
					this.#cellGrid[i].classList.add("invalid")
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	#selectCell(i, cell) {
 | 
			
		||||
		if (this.hasAttribute("readonly") || !this.isActive) return
 | 
			
		||||
		this.#selectedCells.set(i, cell)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user