Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple sub-forms from html not json ? #23

Open
rhaamo opened this issue May 6, 2017 · 2 comments
Open

Multiple sub-forms from html not json ? #23

rhaamo opened this issue May 6, 2017 · 2 comments

Comments

@rhaamo
Copy link
rhaamo commented May 6, 2017

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
Copy link
Author
rhaamo commented May 7, 2017

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 ?

unknwon added a commit that referenced this issue May 21, 2017
@unknwon
Copy link
Contributor
unknwon commented May 21, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants