-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edit table row with stimulus instead of raw javascript
- Loading branch information
Showing
4 changed files
with
36 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,4 @@ | ||
import "@hotwired/turbo-rails" | ||
import "./controllers" | ||
import "@puzzleitc/puzzle-shell"; | ||
import "@puzzleitc/puzzle-shell/style.css"; | ||
|
||
let toggleEditModeButton = document.querySelectorAll('.edit-button'); | ||
let saveButton = document.querySelectorAll('.save-button'); | ||
let cancelButton = document.querySelectorAll('.cancel-button'); | ||
|
||
document.addEventListener('turbo:load', () => { | ||
toggleEditModeButton.forEach((img, index) => { | ||
img.addEventListener("click", () => { | ||
let row = document.getElementById('table-row-' + index); | ||
row.contentEditable = "true"; | ||
row.focus(); | ||
toggleActionButtonDisplay(index, "block"); | ||
img.style.display = "none"; | ||
}); | ||
}); | ||
|
||
cancelButton.forEach((cancel, index) => { | ||
cancel.addEventListener("click", () => { | ||
let row = document.getElementById("table-row-" + index); | ||
row.contentEditable = "false"; | ||
toggleActionButtonDisplay(index, "none"); | ||
document.getElementById("edit-button-" + index).style.display = "block"; | ||
}); | ||
toggleActionButtonDisplay(index, "none"); | ||
}); | ||
}); | ||
|
||
function toggleActionButtonDisplay(id, display) { | ||
document.getElementById("cancel-button-" + id).style.display = display; | ||
document.getElementById("save-button-" + id).style.display = display; | ||
} | ||
import "@puzzleitc/puzzle-shell/style.css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="table" | ||
export default class extends Controller { | ||
static targets = ["row", "editButton" ,"saveButton", "cancelButton"] | ||
connect() { | ||
|
||
} | ||
|
||
editRow() { | ||
this.triggerButtonDisplay("none", "block"); | ||
this.rowTarget.contentEditable = "true"; | ||
this.rowTarget.focus(); | ||
} | ||
|
||
cancelRow() { | ||
this.triggerButtonDisplay("block", "none"); | ||
this.rowTarget.contentEditable = "false"; | ||
} | ||
|
||
triggerButtonDisplay(editButtonDisplay, actionButtonDisplay) { | ||
this.cancelButtonTarget.style.display = actionButtonDisplay; | ||
this.saveButtonTarget.style.display = actionButtonDisplay; | ||
this.editButtonTarget.style.display = editButtonDisplay; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters