-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support for btn input addons #25
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,11 @@ def self.field_helpers_to_test | |
it { expect(form).to match %r{<div class="input-group"><.+?><span class="input-group-addon">Jr</span></div>}m } | ||
end | ||
|
||
context 'given a suffix option that is a button, prints the correct addon wrapper class' do | ||
let(:options) { {suffix: content_tag(:button, 'hey', class: 'btn btn-default')} } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the objects that can be used as prefixes or suffixes are limited, I wouldn't want to expose the generic For instance, right now you can write <%= f.text_field :name, prefix: 'ok' %> The next nice step would be <%= f.text_field :name, prefix: icon(:ok) $>
which I expect not to be working now, not being HTML-safe (I might be wrong, I didn't check). So for the input group button, I'd like the syntax to be <%= f.text_field :name, suffix: button_to('Go', action: 'submit') %> which would be easier to write (and less prone to errors) than the full There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying this PR locally, I found a couple of things:
<%= f.text_field :email, suffix: button_to('Go', signin_path) %> With the current master displays as: After the current PR would display as: Which a little different from the desired behavior: |
||
it { expect(form).to match %r{<div class="input-group"><.+?><span class="input-group-btn"><button class="btn btn-default">hey</button></span></div>}m } | ||
end | ||
|
||
specify 'not given an error, does not apply has-error to the form group' do | ||
expect(form).not_to include 'has-error' | ||
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.
Don't really like having to do that kind of matching, but it was the only I found getting
input-group-btn
to work without providing extra options. Perhaps its just better to provide an optionsbutton: true
or something like that. Any suggestions?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.
Finally I got time to look at this.
I cannot think of a much better solution than what you suggest.
The Bootstrap documentation says:
My understanding is that
.input-group-btn
should be used only if the content is exactly a button.So one solution would be to scan the string for a regex like
%{^<button.+>.+</button>$}
.However, as you point out, the content might be a different DOM element looking like a button, for instance
In any case, all I can think of is a regex-matching of
addon
, similar to what you suggest…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.
Because I don't have a clear opinion about this yet, I'll mark this PR as "version 1.2"!