add description input

This commit is contained in:
rmanach 2025-01-06 11:21:59 +01:00
parent 7d1a042915
commit 1c6b758f0c
3 changed files with 28 additions and 13 deletions

View File

@ -58,14 +58,15 @@ type BookField[T BookFieldType] struct {
} }
type BookForm struct { type BookForm struct {
Name BookField[string] Name BookField[string]
Editor BookField[string] Description BookField[string]
Authors BookField[StrList] Editor BookField[string]
Year BookField[int] Authors BookField[StrList]
Keywords BookField[StrList] Year BookField[int]
File BookField[BookFile] Keywords BookField[StrList]
Error string File BookField[BookFile]
Method string Error string
Method string
} }
func NewBookForm() BookForm { func NewBookForm() BookForm {
@ -73,6 +74,9 @@ func NewBookForm() BookForm {
Name: BookField[string]{ Name: BookField[string]{
Name: "name", Name: "name",
}, },
Description: BookField[string]{
Name: "description",
},
Editor: BookField[string]{ Editor: BookField[string]{
Name: "editor", Name: "editor",
}, },
@ -122,6 +126,8 @@ func extractBookForm(r *http.Request) BookForm {
} }
bf.Name.Value = name bf.Name.Value = name
bf.Description.Value = r.FormValue(bf.Description.Name)
editor := r.FormValue(bf.Editor.Name) editor := r.FormValue(bf.Editor.Name)
if editor == "" { if editor == "" {
bf.Editor.Err = ErrInvalidEditor.Error() bf.Editor.Err = ErrInvalidEditor.Error()

View File

@ -48,8 +48,8 @@ func (e environment) GetDir() string {
func newEnv() environment { func newEnv() environment {
env := environment{ env := environment{
adminUsername: os.Getenv("API_ADMIN_USERNAME"), adminUsername: "test",
adminPassword: os.Getenv("API_ADMIN_PASSWORD"), adminPassword: "test",
isSecure: os.Getenv("API_SECURE") == "true", isSecure: os.Getenv("API_SECURE") == "true",
} }

View File

@ -4,13 +4,22 @@
<div class="main-container"> <div class="main-container">
<div class="form-item"> <div class="form-item">
<div class="form-container"> <div class="form-container">
<label>Book name:</label> <label>Name:</label>
<input type="text" name="name" value="{{.Name.Value}}" /> <input type="text" name="name" value="{{.Name.Value}}" />
</div> </div>
{{ if .Name.Err }} {{ if .Name.Err }}
<div class="error">{{.Name.Err}}</div> <div class="error">{{.Name.Err}}</div>
{{ end }} {{ end }}
</div> </div>
<div class="form-item">
<div class="form-container">
<label>Description:</label>
<textarea rows="10" placeholder="Enter a descrption... (optional)" style="width: 100%;" name="description">{{.Description.Value}}</textarea>
</div>
{{ if .Description.Err }}
<div class="error">{{.Description.Err}}</div>
{{ end }}
</div>
<div class="form-item"> <div class="form-item">
<div class="form-container"> <div class="form-container">
<label>Editor:</label> <label>Editor:</label>
@ -23,7 +32,7 @@
<div class="form-item"> <div class="form-item">
<div class="form-container"> <div class="form-container">
<label>Authors:</label> <label>Authors:</label>
<input type="text" name="authors" value="{{.Authors.Value | join}}" /> <input placeholder="Author one, Author two..." type="text" name="authors" value="{{.Authors.Value | join}}" />
</div> </div>
{{ if .Authors.Err }} {{ if .Authors.Err }}
<div class="error">{{.Authors.Err}}</div> <div class="error">{{.Authors.Err}}</div>
@ -41,7 +50,7 @@
<div class="form-item"> <div class="form-item">
<div class="form-container"> <div class="form-container">
<label>Keywords:</label> <label>Keywords:</label>
<input type="text" name="keywords" value="{{.Keywords.Value | join}}" /> <input placeholder="engineering,music..." type="text" name="keywords" value="{{.Keywords.Value | join}}" />
</div> </div>
{{ if .Keywords.Err }} {{ if .Keywords.Err }}
<div class="error">{{.Keywords.Err}}</div> <div class="error">{{.Keywords.Err}}</div>