renamed confirm page

This commit is contained in:
Bronku 2025-01-31 15:13:21 +01:00
parent 074451cec2
commit 9f858d50ae
4 changed files with 3 additions and 53 deletions

View file

@ -14,7 +14,7 @@ type Controller struct {
// #todo: load all automatically
func (c *Controller) LoadTemplates(fs fs.FS) {
c.tmpl = make(map[string]*template.Template)
c.tmpl["order/post_new"], _ = template.ParseFS(fs, "templates/order/post_new.html")
c.tmpl["order/confirmation"], _ = template.ParseFS(fs, "templates/order/confirmation.html")
c.tmpl["cake/options"], _ = template.ParseFS(fs, "templates/cake/options.html")
}

View file

@ -9,9 +9,9 @@ func (c *Controller) postNewOrder(w http.ResponseWriter, r *http.Request) {
fmt.Println("received Post request: ", r)
err := r.ParseForm()
if err != nil {
_ = c.tmpl["order/post_new"].Execute(w, struct{ Status any }{Status: err})
_ = c.tmpl["order/confirmation"].Execute(w, struct{ Status any }{Status: err})
}
w.WriteHeader(http.StatusAccepted)
fmt.Println(r.Form)
_ = c.tmpl["order/post_new"].Execute(w, struct{ Status any }{Status: r.Form})
_ = c.tmpl["order/confirmation"].Execute(w, struct{ Status any }{Status: r.Form})
}

View file

@ -1,50 +0,0 @@
<form x-show="open" hx-post="order/new" hx-swap="innerHTML" hx-target="#response" id="new_cake_form">
<div>
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" required value="">
</div>
<div>
<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" value="">
</div>
<div>
<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone" value="">
</div>
<div>
<label for="location">Location</label>
<input type="text" id="location" name="location" value="">
</div>
<div>
<label for="paid">Paid</label>
<input type="number" id="paid" name="paid" step="0.01" min="0" value="">
</div>
<select id="dropdown">
<option value="">Select an item...</option>
{{range .Cakes}}
<option value="{{.ID}}">{{.Name}}</option>
{{end}}
</select>
<button type="button" x-on:click="open = false">Cancel</button>
<button type="submit">Submit</button>
<script>
const dropdown = document.getElementById("dropdown")
dropdown.addEventListener("change", function () {
const label = document.createElement('label')
label.innerText = this.options[this.selectedIndex].text
label.setAttribute("for", "cake[" + this.value + "]")
const input = document.createElement('input')
input.setAttribute("type", "number")
input.setAttribute("id", "cake[" + this.value + "]")
input.setAttribute("name", "cake[" + this.value + "]")
input.setAttribute("value", 1)
const selected = document.createElement('div')
selected.appendChild(label)
selected.appendChild(input)
console.log(selected)
const parent = document.getElementById("new_cake_form")
parent.appendChild(selected)
})
</script>
<div id="order_confirmation"></div>
</form>