diff options
author | Mark Powers <mark@marks.kitchen> | 2023-01-30 22:26:19 -0600 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2023-01-30 22:27:26 -0600 |
commit | ad11ec7f93dca356748cb6c8bc49313a7ee7c3d7 (patch) | |
tree | 72418f494cd4b405cecdd5e6fbd539781e0c30e0 /static/new_form.html | |
parent | b6c0e7dbc3b618ecca2449c4395ce857649521cf (diff) |
Add form for new form
Diffstat (limited to 'static/new_form.html')
-rw-r--r-- | static/new_form.html | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/static/new_form.html b/static/new_form.html new file mode 100644 index 0000000..7022d5a --- /dev/null +++ b/static/new_form.html @@ -0,0 +1,74 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + </head> + <body> + <nav></nav> + <div class="main"> + + <div> + <label for="type">Type:</label> + <select name="type" onchange="update_select()"> + <option value="multiple_select">multiple_select</option> + <option value="number">number</option> + <option value="range">range</option> + <option value="textarea">textarea</option> + <option value="text">text</option> + </select> + </div> + + <div> + <label for="prompt">prompt</label> + <input name="prompt" type="text"></input> + </div> + <div> + <label for="prompt_id">prompt_id</label> + <input name="prompt_id" type="text"></input> + </div> + + <div class="range"> + <div> + <label for="min">min</label> + <input name="min" type="text"></input> + </div> + <div> + <label for="max">max</label> + <input name="max" type="text"></input> + </div> + </div> + + <div><button onclick="on_submit()">Submit</button></div> + <script> + async function enqueue_data(path, payload, do_alert=false, timestamp=true){ + if(timestamp){ + payload["timestamp"] = Date.now() + } + await fetch(path, {method: "POST", body: JSON.stringify(payload)}) + if(do_alert){ + alert("saved!") + } + } + function update_select(){ + let v = document.querySelectorAll("select")[0].value + document.querySelectorAll(".range").forEach(el => { + el.style.display = v == "range" ? "block" : "none" + }) + } + function on_submit(){ + let payload = { + "type": document.querySelectorAll("select")[0].value, + } + document.querySelectorAll("input").forEach(el => { + if(el.value.length > 0){ + payload[el.name] = el.value + } + }) + enqueue_data("/submit_new_form", payload, do_alert=true, timestamp=false) + } + window.onload = function(){ + update_select() + } + </script> + </div> + </body> +</html> |