Skip to content
This repository was archived by the owner on Feb 26, 2018. It is now read-only.

Conversation

@dansoppelsa
Copy link

I am using this on a "Member Account" page in an Admin Dashboard that has multiple forms to update specific aspects of a member's account. All forms are being bound to the member object passed to the view.

There are forms for things like:

  • Member's contact info
  • Member's account details (username, user level, account status)
  • Password reset

I was having a problem where if a field failed to validate on the Account Details form, for instance, the Contact Info. form would not be populated on redirect back.

This will solve that issue with multiple bound forms as it will check old input for a specific key, as opposed to just ANY old input, and then fallback to the bound model value.

@adamwathan adamwathan self-assigned this May 11, 2015
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.19%) to 94.41% when pulling 955e894 on SoupBowlWeb:hasOldInputFor into cff7aff on adamwathan:master.

@adamwathan
Copy link
Owner

Hmph good point on the multiple-forms-per-page thing. We used to check for old input this way (based on a specific key) but eventually realized it made more sense to check at a more global level because things like checkboxes might not come through, so say the bound model had a checkbox field set to true, then you unchecked it but there was some validation error, it wouldn't remember the unchecked state because there was no old input for that key since unchecked checkboxes don't get passed in.

I wonder if a better overall solution is to somehow sandbox each form builder instance to it's own set of old input? Like some sort of shit prefix or something per form in the old input keys so they can't stomp on each other. And then make sure each form is using it's own builder. And somehow remember which builder had which prefix and pass them through. Maybe even just an optional parameter in the open call that's like a form namespace? So you can omit it if you just have one form, but for a complex page with multiple forms you can name the forms and it'll namespace the old input based on the form name. I think that might be a good approach? Rambling brainstorming in a PR comment FTW.

Why is this shit so fucking complicated, it's fucking FORMS. Jesus.

@dansoppelsa
Copy link
Author

Haha, a very thorough and thought provoking reply.

I had the exact same thought, a Builder instance per form as opposed to a global Builder for multiple forms. Like you said this would solve the possible issue of inputs with the same name on different forms.

@jesseleite
Copy link
Contributor

jesseleite commented Dec 7, 2016

I think the form namespacing implementation in #109 should cover this.

@adamwathan adamwathan closed this Jan 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants