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

Use default on record filter when given an empty string #503

Closed
solebared opened this issue Apr 3, 2021 · 2 comments
Closed

Use default on record filter when given an empty string #503

solebared opened this issue Apr 3, 2021 · 2 comments
Assignees

Comments

@solebared
Copy link

Thanks for fixing #412 in v4, this really does help with using AI for form objects.

It appears however that 5a5337c did not cover record filters? Perhaps this was intentional, but i think treating a blank/empty input string as nil could also apply here.

For example, say we have a form for creating an Issue,

class IssueForm < ActiveInteraction::Base
  record :assignee, class: Contributor, default: nil
  # ...
end

where assignee is selected with a dropdown on the frontend, but is optional.

When the user omits the assignee, params would still include assignee: ''.
Passing params directly into the interactor would then fail:

IssueForm.run!(assignee: '')  #=> ActiveInteraction::InvalidInteractionError (Assignee is not a valid record)

I think it would be intuitive for AI to assign the default value here, as is the case with other filters.

@solebared
Copy link
Author

Attempted to also demonstrate this with a unit test in this commit, though i'm not confident this is the right place to specify the behavior i'm proposing.

solebared added a commit to rubyforgood/mutual-aid that referenced this issue Apr 3, 2021
`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 added a commit to rubyforgood/mutual-aid that referenced this issue Apr 3, 2021
`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
@AaronLasseigne AaronLasseigne self-assigned this Dec 30, 2021
@AaronLasseigne AaronLasseigne added bug and removed bug labels Dec 30, 2021
@AaronLasseigne
Copy link
Owner

This will be in the 5.0.0 release.

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

2 participants