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

allow blank labels for fae_content_form #360

Merged
merged 2 commits into from
Dec 5, 2017
Merged

Conversation

andrewdang17
Copy link
Contributor

@andrewdang17 andrewdang17 commented Dec 4, 2017

This is just a quick fix so I can get ticket done for a client this week. I think later on all that logic in _content_form.html.slim should be refactored out to be separate from the partial so that you just have to pass an options in rather than every possible variable since everything is a bit dependent on each other right now and relies on a lot of conditionals.

@@ -1,5 +1,6 @@
ruby:
require_locals ['attribute', 'f'], local_assigns
blank_label = !label || label == '' unless label.nil?
label ||= attribute.to_s.titleize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewdang17 We're starting to spread the label logic all over this file. The label_adjusted assignment on line 13 is where the full label get's built, so I think that's where the conditional logic should live. There should be no need to execute that logic if we're just setting it to false later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree I just did it this way because I didn't want to add more if/unless statements to lines 12-22 or have to wrap the whole thing in an if statement

@@ -1,5 +1,6 @@
ruby:
require_locals ['attribute', 'f'], local_assigns
blank_label = !label || label == '' unless label.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this line difficult to interpret. If we focus on supporting label: false, then it could look something like:

has_label = !local_assigns[:label].eql?(false)

This is a pattern we've using in other partials too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that looks better. label: false was the only way to remove the label for simpleform hence the check for false or an empty string

Copy link
Contributor Author

@andrewdang17 andrewdang17 Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesmk what do you about using this instead?
has_label = ![false, ''].include?(local_assigns[:label])

The problem with your way is that if label: false, then !local_assigns[:label] will return true when really it should be false.

@andrewdang17
Copy link
Contributor Author

@jamesmk updated

@jamesmk jamesmk merged commit f558875 into master Dec 5, 2017
@jamesmk jamesmk deleted the allow-blank-labels branch December 5, 2017 21:57
@andrewdang17 andrewdang17 restored the allow-blank-labels branch December 8, 2017 23:10
@andrewdang17 andrewdang17 deleted the allow-blank-labels branch December 8, 2017 23:59
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