Closed mrLSD closed 5 years ago
@mrLSD removing "[]" should works!
@dashaus, Thank you for the response and great library!
In Usage section:
- Use [
] for access to index of a slice/array. (i.e, struct.array[0]). If the array/slice is the last field of the path, it is not necessary to indicate the index
as I understand, and it's common practice: "field[]"
Without "[]" it work pretty well.
But as I mentioned before: it's common and useful practice: "field[]"
because it is indicating Array
.
Do you plan implement that?
I can implement it if this not affects to the performance (I think that it no should to affect). In the next days, I go do it!
Thank you for the response! I have additional question, but off-topic. I don't know, is it about new issue: How to fetch errors to end-user? For example:
dec := formam.NewDecoder(&formam.DecoderOptions{TagName: "formam"})
if err := dec.Decode(values, &company); err != nil {
fmt.Printf("Error: %#v\n\n", err.Error())
}
But I need notify HTML form about problem:
Because err.Error()
return only string with first error.
The error message produced by formam should be useful for the developer, not for end-user, so when the decoder fails I think that you should to display a 500 status error, but if the error is because the user introduces incorrect input then should be validated by a validation package like monoculum/valider but my package is not finished so I don't recommend used it until it finished and to use another validation package.
@mrLSD Try to set tag in your struct:
`formam:"foundation[]"`
Maybe it will help
How to use not indexed arrays?
From your example, when I trying change:
to
I got:
runtime error: slice bounds out of range