feat: set default expiration in select #28

Open
tapiron wants to merge 1 commit from tapiron/coller:feat/display_default_expiration_in_form into main
2 changed files with 3 additions and 1 deletions
Showing only changes of commit 16945d488a - Show all commits

View file

@ -189,6 +189,7 @@ type PageData struct {
Title string
Version string
Expirations []int
Expiration int
Languages []string
Err error
URL string
@ -426,6 +427,7 @@ func (s *Server) Start() error {
p := PageData{
Title: s.config.Title,
Expirations: s.config.Expirations,
Expiration: s.config.Expiration,
Languages: s.config.Languages,
}

View file

@ -36,7 +36,7 @@
</div>
<div class="col">
<select class="form-select" aria-label="Expiration" id="expiration" name="expiration">
<option selected="selected" disabled>Expiration</option>
<option selected="selected" disabled>{{HumanDuration .Expiration}}</option>

Expiration is included in Expirations resulting in a duplicate entry in the list.

Wouldn't it be better to use a selected="selected" attribute when the expiration is the default one instead?

Something like:

<option disabled>Expiration</option>
{{range .Expirations}}
 <option {{if eq . .Expiration}}selected="selected"{{end}} value="{{.}}">{{HumanDuration .}}</option>
{{end}}

I'm not sure about the scope of the variables here but that should be doable. That way, we'll still see it's an expiration thanks to the disabled option but it would automatically select the default value set on the server.

Expiration is included in Expirations resulting in a duplicate entry in the list. Wouldn't it be better to use a `selected="selected"` attribute when the expiration is the default one instead? Something like: ```html <option disabled>Expiration</option> {{range .Expirations}} <option {{if eq . .Expiration}}selected="selected"{{end}} value="{{.}}">{{HumanDuration .}}</option> {{end}} ``` I'm not sure about the scope of the variables here but that should be doable. That way, we'll still see it's an expiration thanks to the disabled option but it would automatically select the default value set on the server.
{{range .Expirations}}
<option value="{{.}}">{{HumanDuration .}}</option>
{{end}}