Add command route to try index order form
This commit is contained in:
parent
ea3bc60ac3
commit
ceae501835
2 changed files with 41 additions and 0 deletions
32
public/javascripts/index.js
Normal file
32
public/javascripts/index.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
const commandAction = document.getElementById("command-action");
|
||||||
|
const addButton = document.getElementById("add-command");
|
||||||
|
const rmButton = document.getElementById("remove-command");
|
||||||
|
|
||||||
|
function lastCommandId() {
|
||||||
|
let list = document.querySelectorAll("div.command h2");
|
||||||
|
return parseInt(list[list.length-1].innerText.replace("Command ", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
addButton.addEventListener("click", () => {
|
||||||
|
let id = lastCommandId() + 1;
|
||||||
|
commandAction.insertAdjacentHTML("beforebegin", `<div id="command${id}" class="command">
|
||||||
|
<h2>Command ${id}</h2>
|
||||||
|
<div class="field">
|
||||||
|
<label for="sandwich">Sandwich:</label>
|
||||||
|
<input id="sandwich" type="list" list="sandwich-list" name="sandwich${id}" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="day">Day:</label>
|
||||||
|
<input id="day" type="list" list="date-list" name="date${id}" required>
|
||||||
|
</div>
|
||||||
|
</div>`);
|
||||||
|
document.getElementById("command"+lastCommandId()).scrollIntoView({behavior: "smooth"});
|
||||||
|
rmButton.classList.remove("hide");
|
||||||
|
});
|
||||||
|
|
||||||
|
rmButton.addEventListener("click", () => {
|
||||||
|
let id = lastCommandId();
|
||||||
|
document.getElementById("command"+id).remove();
|
||||||
|
if (id === 2)
|
||||||
|
rmButton.classList.add("hide");
|
||||||
|
});
|
9
routes/command.js
Normal file
9
routes/command.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
let express = require("express");
|
||||||
|
let router = express.Router();
|
||||||
|
|
||||||
|
/* GET home page. */
|
||||||
|
router.post("/", (req, res) => {
|
||||||
|
console.log(req.body);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
Reference in a new issue