Fixing not working database/new admin endpoint

This commit is contained in:
Fabian Stamm
2019-10-11 19:35:36 +02:00
parent 65d1710902
commit 6036556a37
3 changed files with 25 additions and 22 deletions

View File

@ -29,24 +29,24 @@
<div id="message"> </div>
<form id="f1" action="JavaScript:void(null)">
{{#each fields}}
<div class="input-group">
<label>{{label}}</label>
{{#ifCond type "===" "text"}}
<input type="text" placeholder="{{label}}" name="{{name}}" value="{{value}}" />
{{/ifCond}}
<div class="input-group">
<label>{{label}}</label>
{{#ifCond type "===" "text"}}
<input type="text" placeholder="{{label}}" name="{{name}}" value="{{value}}" />
{{/ifCond}}
{{#ifCond type "===" "number"}}
<input type="number" placeholder="{{label}}" name="{{name}}" value="{{value}}" />
{{/ifCond}}
{{#ifCond type "===" "number"}}
<input type="number" placeholder="{{label}}" name="{{name}}" value="{{value}}" />
{{/ifCond}}
{{#ifCond type "===" "boolean"}}
<input type="checkbox" name="{{name}}" checked="{{value}}" />
{{/ifCond}}
{{#ifCond type "===" "boolean"}}
<input type="checkbox" name="{{name}}" checked="{{value}}" />
{{/ifCond}}
{{#ifCond type "===" "textarea"}}
<textarea class="inp" name="{{name}}" rows="20">{{value}}</textarea>
{{/ifCond}}
</div>
{{#ifCond type "===" "textarea"}}
<textarea class="inp" name="{{name}}" rows="20">{{value}}</textarea>
{{/ifCond}}
</div>
{{/each}}
<button class="btn btn-primary" onclick="submitData()">Submit</button>
@ -55,14 +55,17 @@
</div>
<script>
const url = "{{url}}";
let u = new URL("{{url}}", window.location.origin);
let key = new URL(window.location.href).searchParams.get("key");
if (key)
u.searchParams.set("key", key);
const message = document.getElementById("message");
const form = document.getElementById("f1");
function submitData() {
let res = {};
Array.from(new FormData(form).entries()).forEach(([name, value]) => res[name] = value);
fetch(url, {
fetch(u.href, {
method: "POST",
headers: {
"content-type": "application/json"