binding icon indicating copy to clipboard operation
binding copied to clipboard

Multiple sub-forms from html not json ?

Open rhaamo opened this issue 8 years ago • 2 comments

It seems that the JSON part supports having multiple "sub-forms" (slices of structs ?).

I would like to have something like (not File Uploads here, plain HTML input forms):

type ItemFile struct {
    Filename string
    Content string `binding:"Required;Text"`
}
type Item struct {
    Description string `binding:"Required"`
    Files []ItemFile // ?
}

Is it possible to do that ? how should I use the "ItemFile" and naming in html for fields names ?

rhaamo avatar May 06 '17 23:05 rhaamo

I tried another way with:

type Item struct {
	Description string `binding:"MaxSize(255)"`
	IsPublic    bool   `binding:"Default:1"`
	FilesFilename	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
	FilesContent	[]string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
}

If I set Description to Required, submitting a form with empty fields threw an error (expected). If I leave the struct as-is (no Required for Description, only Files Contents and names), and submit form with files_* empty, it threw no errors. (it should)

I found issue #3 but it does seems to only apply to JSON format parser.

Is there any way to do Validation on slices items builtin in macaron/binding or do I need to make them myself after the non-slice fields validation ?

rhaamo avatar May 07 '17 09:05 rhaamo

Hi, I pushed a patch to fix Required check for slice, please help test!

unknwon avatar May 21 '17 10:05 unknwon