gorilla / schema

Package gorilla/schema fills a struct with form values.
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
1.37k stars 227 forks source link

[bug] help Empty strings in an array #172

Closed GuzhavinAleksey closed 3 years ago

GuzhavinAleksey commented 3 years ago

Code:

type Study_visits struct {
    Visits []Visit
}

type Visit struct {
    ID_study       string
    Study_visit    string

}

        err := c.Request.ParseForm()
        if err != nil {
            // Handle error
        }
        decoder := schema.NewDecoder()
        decoder.ZeroEmpty(true)
        visits_fn := new(Study_visits)
        decoder.Decode(visits_fn, c.Request.PostForm)

        fmt.Println("1", visits_fn.Visits)

form

 <form method="POST" action="/overview_department/action_timetable/{{ .id }}/visit_post">
                              <input type="hidden" name="Visits.11.ID_study" value="11">
                                  <select class="form-control js-Study_visit js-states" id="Study_visit" required name="Visits.11.Study_visit">
                                      <option value="yes">yes</option> 
                                      <option value="no">no</option>                                             
                                   </select>
                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Sent
                                </button>
                            </div>
                        </div>
                    </form>

Output 1 [{ } { } { } { } { } { } { } { } { } { } { } {11 yes }]

Instead of 11, the record ID is indicated displays eleven blank lines, how can this be avoided?