Skip to content

Commit

Permalink
Submit button local functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchegm committed Jun 27, 2024
1 parent b495176 commit 948caa2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ for (const cancelButton of cancelButtons) {
cancelButton.addEventListener("click", handleCancelClick);
};

function handleSubmitClick(event) {
const rowId = getRowId(event.srcElement.id);
// Toggle visibilities of buttons.
toggleVisible(event.srcElement.id);
toggleAllOfSame("button[id^='edit-button-']");
toggleAllOfSame("button[id^='cancel-button-" + CSS.escape(rowId) + "']");
toggleAllOfSame("div[id$=" + CSS.escape(rowId) + "]");

// Replace cancelled input text with existing cell text.
var allInputs = document.querySelectorAll("input");
var allTextCells = document.querySelectorAll("div[id$='cell-text-" + CSS.escape(rowId) + "']");
for (let i = 0; i < allTextCells.length; i++) {
allTextCells[i].textContent = allInputs[i].value;
};
};
// Get a NodeList Obj of all cancel buttons, add EventListener to each.
var submitButtons = document.querySelectorAll("button[id^='submit-button-']");
for (const submitButton of submitButtons) {
submitButton.addEventListener("click", handleSubmitClick);
};

// Helper function to get rowId.
function getRowId(idName) {
const rowId = idName.slice(idName.lastIndexOf("-") + 1,idName.length);
Expand Down
3 changes: 2 additions & 1 deletion src/static/simple.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ button,
max-width: 100%;
display: inline-block;
}

textarea,
select,
input {
Expand Down Expand Up @@ -742,4 +743,4 @@ input {
background: #04AA6D;
color : white;
border-color: #04AA6D;
}
}

0 comments on commit 948caa2

Please sign in to comment.