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

Properly support optional location_type on submission form #922

Merged

Conversation

solebared
Copy link
Collaborator

Why

While working to make location optional when creating a CommunityResource, i ran into a bug in our LocationForm. If location_type is not selected on the front end, the form raises an InvalidInteractionError, caused by record filters not accepting an empty string value (location_type: '' in params).

I believe this should really be fixed upstream, but in the meantime, this PR implements a workaround.

Note that we weren't running into this on the Ask|Offer form because it doesn't allow location_type to be omitted; that form only shows the field once a user provides an address and then enlists the browser to ensure it's populated.

What

  • Upgrade active_interaction to v4, to leverage improved form support. See the section titled 'Blank Values Treated As nil For Filters' in the release notes
  • Use an integer filter instead of a record filter, which correctly coerces '' to the default value (nil).

How

We can get away with not looking up the LocationType record ourselves and instead setting just the id on the location object. There's a tiny bit of logic required to align param names here because i didn't want to rename the param from location_type to location_type_id all the way up the stack.

Testing

  • Modified params in submission_form_spec.rb to simulate location_type: ''.

Next Steps

?

Outstanding Questions, Concerns and Other Notes

?

Pre-Merge Checklist

  • Security & accessibility have been considered
  • Tests have been added, or an explanation has been given why the features cannot be tested
  • Documentation and comments have been added to the codebase where required
  • Outstanding questions and concerns have been resolved
  • Any next steps have been turned into Issues or Discussions as appropriate

Improves form support. See the section titled 'Blank Values Treated
As nil For Filters' in the release notes:
https://github.com/AaronLasseigne/active_interaction/releases/tag/v4.0.0
@solebared
Copy link
Collaborator Author

/cc @Connieh1 , this is where i landed with our work from thursday night ^^ 🙃 .

`active_interaction` doesn't coerce an empty string value to the default
value on `record` filters[1]. This causes the form to break on any form
where `location_type` is optional (eg CommunityResources#create).

We hadn't run into this on the Ask|Offer form because we only show the
location_type input once the user provides an address, and then rely on
the browser to enforce that it's populated.

[1] AaronLasseigne/active_interaction#503
@solebared solebared force-pushed the properly-support-optional-location-on-submission-form branch from 5aa7485 to b68799a Compare April 3, 2021 15:15
@solebared solebared merged commit 44d618c into main Apr 3, 2021
@solebared solebared deleted the properly-support-optional-location-on-submission-form branch April 3, 2021 16:13
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

Successfully merging this pull request may close these issues.

2 participants