feat: set default expiration in select #28

Merged
jriou merged 2 commits from tapiron/coller:feat/display_default_expiration_in_form into main 2025-09-15 06:51:17 +02:00
Showing only changes of commit ba53cfda22 - Show all commits

fix: avoid double options

Thibault Piron 2025-09-14 18:46:31 +02:00
Signed by untrusted user who does not match committer: tapiron
GPG key ID: 37EE240037F90B38

View file

@ -36,9 +36,9 @@
</div> </div>
<div class="col"> <div class="col">
<select class="form-select" aria-label="Expiration" id="expiration" name="expiration"> <select class="form-select" aria-label="Expiration" id="expiration" name="expiration">
<option selected="selected" disabled>{{HumanDuration .Expiration}}</option> <option disabled>Expiration</option>
tapiron marked this conversation as resolved Outdated

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.

Yes, it's better like this, done (just used variable instead of implicit "." to be easier to read)

Yes, it's better like this, done (just used variable instead of implicit "." to be easier to read)
{{range .Expirations}} {{range $exp := .Expirations}}
<option value="{{.}}">{{HumanDuration .}}</option> <option {{ if eq $exp $.Expiration }}selected="selected"{{end}} value="{{$exp}}">{{HumanDuration $exp}}</option>
{{end}} {{end}}
</select> </select>
</div> </div>