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

Using df-snap's method field is counter intuitive #116

Open
MichaelXavier opened this issue May 4, 2015 · 2 comments
Open

Using df-snap's method field is counter intuitive #116

MichaelXavier opened this issue May 4, 2015 · 2 comments

Comments

@MichaelXavier
Copy link

This is more of a usability issue but I thought it was worth mentioning since it has tripped me up twice writing forms at work using digestive-functors-snap. I figure if the lesson didn't stick in my head after the first time there may be a problem.

Right now it seems like digestive-functors-snap uses the request's HTTP method to distinguish between a form render (GET) and a form submission (POST). Semantically this is probably not the best idea. It is perfectly reasonable to submit a form with a GET request, such as if you're submitting a search form to a RESTful service. If the end user doesn't remember this, the form just returns a const Nothing essentially and both times I hit this issue I assumed it was a parse error.

One way to solve this is to not use the request method but instead use the presence of the expected parameters to determine if a form was submitted or not. I'm not sure if there are edge cases there that would make this ambiguous.

Even if we wanted to stick with manually telling the form whether it was being submitted or rendered, the way you do it is really confusing. You could be in a GET action and if you want to tell the form it is being submitted you have to do defaultSnapFormConfig { method = Just Post}. That solution eluded me twice because it doesn't make sense. You're not in a POST request. It would be much more self-documenting if you did something like defaultSnapFormConfig { mode = Just Submitted} or something like that.

Interested to hear your opinions on this. Thanks!

@cimmanon
Copy link
Contributor

It's worth pointing out that checkboxes don't behave as expected when using defaultSnapFormConfig { method = Just Post }. Consider the following form:

fooSearchForm :: Monad m => Form Text m (Maybe Text, Maybe Text, Bool)
fooSearchForm = ( , , )
	<$> "code" .: optionalText Nothing
	<*> "keyword" .: optionalText Nothing
	<*> "is_core" .: bool (Just True)

If this form is run using the default runForm function, the initial state of the "is_core" field is checked. When run using a custom SnapFormConfig to force it to process on GET requests, the initial state of the "is_core" field is unchecked. I understand why this happens, but it is undesirable behavior.

@chrissound
Copy link

chrissound commented Aug 7, 2017

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

No branches or pull requests

3 participants