-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Make options_for_select generic #295
Conversation
Maybe the field : LuckyRecord::AllowedField, select_options : Array(Tuple(String, Nil)
# Or if the AllowedField needs a type
field : LuckyRecord::AllowedField(Object?), select_options : Array(Tuple(String, Nil) I think this might work. I'll try it out later since this PR is not a priority |
Documenting this method, and realized that it's restrictive. This PR fixes it, so maybe we can revisit this? I think doing |
Thanks for brining this back up. Now that I look at it, I think having nil is a-ok. What if you want an option like "Disassociate user" or something. Then you should be able to do that by setting the value to nil. So I think if this is rebased it can be merged as-is! Thoughts? |
Yeah, that makes sense. Does this support a way to set the label like how rails has the |
No it doesn't so we'd have to document that. I think what would be even better is a separate method rather than yet another option (Rails helpers have too many options IMO). # If one is chosen then don't render anything, if not render the prompt
select_prompt op.country, "Select a country"
select_options op.country, # blah blah blah For including a blank item I'd add another tuple manually: Thoughts? |
Totally agree on the option bloat. I love that idea of a separate method for adding a prompt option. select_tag(op.opts) do
select_prompt("Select an option")
options_for_select(op.opts, my_options)
end |
Yeah that looks good! Only change is |
80f290a
to
edd16dd
Compare
Ready for re-review. Could you create an issue for adding |
spec/lucky/select_helpers_spec.cr
Outdated
@@ -41,14 +41,14 @@ describe Lucky::SelectHelpers do | |||
end | |||
|
|||
it "renders options" do | |||
view.render_options(form.company_id, [{"Volvo", 2}, {"BMW", 3}]) | |||
view.render_options(form.company_id, [{"Volvo", "2"}, {"BMW", "3"}]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean it always needs to be Tuple(String, String)
? I'm just thinking of the example from a query
CarQuery.new.all.map do |car|
{car.make, car.id.to_s}
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! It means that it has to be whatever the type is on the attribute. In this case company_id
is an attribute with the String type. I can change it to Int32 though so this makes more sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok. I like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, this looks great to me!
Closes #292 This works, the problem is some Fields are nilable, which would mean the second item in the tuple would be nilable. That's probably not what the user wants. On the other hand, it seems unlikely that a `nil` option would end up there.
edd16dd
to
dc2e03a
Compare
Closes #292
This works, the problem is some Fields are nilable, which would mean the
second item in the tuple would be nilable. That's probably not what the
user wants. On the other hand, it seems unlikely that a
nil
optionwould end up there.