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 {
Name BookField[string]
Editor BookField[string]
Authors BookField[StrList]
Year BookField[int]
Keywords BookField[StrList]
File BookField[BookFile]
Error string
Method string
Name BookField[string]
Description BookField[string]
Editor BookField[string]
Authors BookField[StrList]
Year BookField[int]
Keywords BookField[StrList]
File BookField[BookFile]
Error string
Method string
}
func NewBookForm() BookForm {
@ -73,6 +74,9 @@ func NewBookForm() BookForm {
Name: BookField[string]{
Name: "name",
},
Description: BookField[string]{
Name: "description",
},
Editor: BookField[string]{
Name: "editor",
},
@ -122,6 +126,8 @@ func extractBookForm(r *http.Request) BookForm {
}
bf.Name.Value = name
bf.Description.Value = r.FormValue(bf.Description.Name)
editor := r.FormValue(bf.Editor.Name)
if editor == "" {
bf.Editor.Err = ErrInvalidEditor.Error()

View File

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

View File

@ -4,13 +4,22 @@
<div class="main-container">
<div class="form-item">
<div class="form-container">
<label>Book name:</label>
<label>Name:</label>
<input type="text" name="name" value="{{.Name.Value}}" />
</div>
{{ if .Name.Err }}
<div class="error">{{.Name.Err}}</div>
{{ end }}
</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-container">
<label>Editor:</label>
@ -23,7 +32,7 @@
<div class="form-item">
<div class="form-container">
<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>
{{ if .Authors.Err }}
<div class="error">{{.Authors.Err}}</div>
@ -41,7 +50,7 @@
<div class="form-item">
<div class="form-container">
<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>
{{ if .Keywords.Err }}
<div class="error">{{.Keywords.Err}}</div>