Structの配列初期化
type Book struct {
Name []string
}
bookNum := 2
books := Book{Name: make([]string, bookNum)}
books := Book{
Name: []string{"hoge", "fuga"},
}
RevelのTemplateでFormを作る
{{if gt .bookNum 2 }}
{{$sa := index .books.Name 2}}
{{with $field := field "books.Name[2]" .}}
<p class="{{$field.ErrorClass}}">
<strong>Check In Date:</strong>
<input type="text" size="10" name="{{$field.Name}}" class="datepicker" value="{{firstof $field.Flash $sa}}">
* <span class="error">{{$field.Error}}</span>
</p>
{{end}}
{{end}}
RevelでValidationしてみる
for index, book := range books.Name {
keyName := "books.Name[" + strconv.Itoa(index) + "]"
c.Validation.Required(book).Key(keyName).Message("Your name is required!")
c.Validation.MinSize(book, 3).Key(keyName).Message("Your name is not long enough!")
}