Arreglar etiquetas "form"

Estas etiquetas no soportan "omitempty"
This commit is contained in:
danoloan10 2023-10-14 20:02:06 +02:00
parent 78f3e96aa6
commit db76fd1d3a
4 changed files with 15 additions and 9 deletions

View File

@ -47,7 +47,13 @@ func (renderer *TemplateRenderer) Render(w io.Writer, name string, data interfac
func (template Template) TemplateController(c echo.Context) (err error) {
entries, err := list.GetEntries()
if err == nil {
err = c.Render(http.StatusOK, string(template), entries)
err = c.Render(http.StatusOK, string(template), struct {
Entries []*storage.Entry
Today storage.JSTime
}{
Entries: entries,
Today: storage.JSTime(time.Now()),
})
}
return
}

View File

@ -5,11 +5,11 @@ import "fmt"
type (
Entry struct {
Artist string `json:"artist" form:"artist"`
Linkto string `json:"linkto" form:"linkto,omitempty"`
Track string `json:"track" form:"track,omitempty"`
Album string `json:"album" form:"album,omitempty"`
Cover string `json:"cover" form:"cover,omitempty"`
Date JSTime `json:"date" form:"date,omitempty"`
Linkto string `json:"linkto" form:"linkto"`
Track string `json:"track" form:"track"`
Album string `json:"album" form:"album"`
Cover string `json:"cover" form:"cover"`
Date JSTime `json:"date" form:"date"`
}
)

View File

@ -21,7 +21,7 @@
<div class="form-elem"> <input name="track" type="text" placeholder="Canción"/> </div>
<div class="form-elem"> <input name="album" type="text" placeholder="Álbum"/> </div>
<div class="form-elem"> <input name="linkto" type="text" placeholder="Enlace"/> </div>
<div class="form-elem"> <input name="date" type="date" placeholder="Fecha"/> </div>
<div class="form-elem"> <input name="date" type="date" placeholder="Fecha" value="{{ .Today.String }}"/> </div>
<hr/>
<input type="submit" value="Añadir">
</form>
@ -35,7 +35,7 @@
</button>
<div class="action">
<div class="scroll">
{{ range $index, $elem := . }}
{{ range $index, $elem := .Entries }}
<a href="del/{{ $index }}" class="data-elem">
{{ $elem.Showname }}
</a>

View File

@ -147,7 +147,7 @@ nav > a:hover {
<a href="admin/">Zona del admin <span class="emoji">😎</span></a>
</nav>
<main>
{{ range . }}
{{ range .Entries }}
<a href="{{ .Linkto }}">
<div class="elem">
<img src="{{ .Cover }}" class="cover" loading="lazy">