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

Flash and Slices #191

Closed
adam-frisby opened this issue Jun 19, 2013 · 3 comments
Closed

Flash and Slices #191

adam-frisby opened this issue Jun 19, 2013 · 3 comments

Comments

@adam-frisby
Copy link
Contributor

I have a multi-select html form element which allows a user to select multiple categories. On form validation error, I would like to be able to reselect the categories the user had already selected.

Issues:

First, when calling FlashParams() with a slice parameter, the key becomes "slice[]", but when attempting to access the flash variable in a template via {{.slice[]}} results in "bad character U+005B '['"

Second, only the first value in the slice is set in the flash cookie. There is the limitation of flash being a string map, so the multiple values would have to be represented as a string. I was thinking you could escape backslashes and commas and use a comma separated list. This could be made into is own function that FlashParams() can call or can call when manually setting flash data. A template function would then be required to iterate over the comma separated list.

I think its a problem worth solving sooner or later. Any feedback would be appreciated.

@robfig
Copy link
Contributor

robfig commented Jun 19, 2013

I agree, this is a good issue to solve.

The first error you point out is a Go templates thing -- to use a special character as an index you have to use the "index" function: {{index . "slice[]"}}

For, representing a multi-select value, I think your suggestion about serializing to CSV could be the best. (e.g. using "encoding/csv"), and having something (a tag? a method on flash?) to deserialize it to []string

@brendensoares
Copy link
Member

TODO

@notzippy
Copy link
Collaborator

Adding a session manager to handle objects will cover this

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

No branches or pull requests

5 participants