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

Integration Bootstrap3 #864

Closed
wants to merge 11 commits into from

Conversation

zlx
Copy link

@zlx zlx commented Aug 24, 2013

Integration Bootstrap3

You need not to change any codebase to migration from bootstrap 2 to bootstrap 3

@zlx
Copy link
Author

zlx commented Aug 24, 2013

Migrating step:

  1. rails g simple_form:install --bootstrap3
  2. use controls_html replace input_html in form
  3. change css class according to migration from 2 to 3

OK

@@ -50,7 +50,7 @@ def with_full_error_for(object, *args)
end

test 'error should be able to pass html options' do
with_error_for @user, :name, id: 'error', class: 'yay'
with_error_for(@user, :name, id: 'error', class: 'yay')
Copy link

Choose a reason for hiding this comment

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

this isn't reallly required for the PR is it? You should remove this change as it will make it easier to merge.

def options_classes(klass, opts)
# chech if use bootstrap3 stylesheet
# replace default class with options[:class]
if SimpleForm.default_wrapper == :bootstrap3 && opts[:class] &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately we can't and will not make Simple Form code dependent of twitter bootstrap. All the bootstrap configuration must be in the application code, not Simple Form.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, It's ugly

but in bootstrap 3, you must control input size on div(bootstrap2 on input), so if we config a default class eg: col-lg-2

now, if you add class on input, it will use the large size not the newer.

I do not find a better way to handle this case. Do you have any advice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is the case so we should not add anything to Simple Form and let the user configure the class when calling the input method.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, It mean user must config every input.

It looks so bad for me. I like default config and user can use outbox

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion it is the right and the best path. Simple Form can't and
won't be coupled with bootstrap. It is a independent project is the
bootstrap configurations are only a facility.

We have to give generic configurations like the wrappers API and the input
options.

If we have to change Simple Form every time a new bootstrap version is
released I sincerely prefer to remove all the bootstrap support.
On Aug 24, 2013 10:31 PM, "soffolk" notifications@github.com wrote:

In lib/simple_form/wrappers/many.rb:

@@ -68,6 +68,19 @@ def html_options(options)
def html_classes(input, options)
@defaults[:class].dup
end
+

  •  # check wrappers is bootstrap3
    
  •  # maybe better to if use bootstrap3 wrappers
    
  •  def options_classes(klass, opts)
    
  •    # chech if use bootstrap3 stylesheet
    
  •    # replace default class with options[:class]
    
  •    if SimpleForm.default_wrapper == :bootstrap3 && opts[:class] &&
    

Oh, It mean user must config every input.

It look so bad for me. I like default config and user can use outbox


Reply to this email directly or view it on GitHubhttps://github.com//pull/864/files#r5967279
.

Copy link
Author

Choose a reason for hiding this comment

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

You are right! I think I can create a new repo to integration bootstrap 3 with simple_form

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is needed. I'm pretty sure that with the current
features is possible to use simple form with Twitter Bootstrap 3.
On Aug 24, 2013 10:49 PM, "soffolk" notifications@github.com wrote:

In lib/simple_form/wrappers/many.rb:

@@ -68,6 +68,19 @@ def html_options(options)
def html_classes(input, options)
@defaults[:class].dup
end
+

  •  # check wrappers is bootstrap3
    
  •  # maybe better to if use bootstrap3 wrappers
    
  •  def options_classes(klass, opts)
    
  •    # chech if use bootstrap3 stylesheet
    
  •    # replace default class with options[:class]
    
  •    if SimpleForm.default_wrapper == :bootstrap3 && opts[:class] &&
    

You are right! I think I can create a new repo to integration bootstrap 3
with simple_form


Reply to this email directly or view it on GitHubhttps://github.com//pull/864/files#r5967304
.

Copy link
Author

Choose a reason for hiding this comment

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

I think I must research the simple_form source code deeply for integration more nice. or someone can do it


```erb
<%= simple_form_for @user do |f| %>
<%= f.input :username, controls_html: {class: 'col-lg-5'} %> # => <div class='col-lg-4'><input class='string .../></div>

Choose a reason for hiding this comment

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

Should be class='col-lg-5' instead class='col-lg-4', right?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, my typo!

Because I do not find the way to integration bootstrap3 without check bootstrap3 in simple_form codebase, it'll not be merged!

If you want to use it, may be checkout my integration_bootstrap3 or simple_form_bootstrap3

@adamico
Copy link

adamico commented Aug 30, 2013

This is the initializer I'm using for Bootstrap 3 https://gist.github.com/adamico/6387890, more details at http://stabco.tumblr.com/post/59760641051/simple-form-bootstrap3-integration

@fabianoalmeida
Copy link

Nice @adamico! 👍

@caarlos0
Copy link

caarlos0 commented Sep 6, 2013

hey @adamico , how you solved the inline checkbox issue?

@MrHubble
Copy link

MrHubble commented Sep 6, 2013

Do we need to be using Rails 4 to implement the @adamico solution? In my gemfile I have: gem 'simple_form', '~> 3.0.0.rc'

When I run bundle update simple_form I get:

Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
rails (= 3.2.13) ruby depends on
actionpack (= 3.2.13) ruby

simple_form (~> 3.0.0.rc) ruby depends on
  actionpack (4.0.0.rc1)

@adamico
Copy link

adamico commented Sep 6, 2013

@caarlos0 , er... I'm not using the inline checkbox/radio right now. I think you should write a custom input for these. Maybe this issue should be referenced at this one #857 whose discussion is far more advanced, methinks.

@adamico
Copy link

adamico commented Sep 6, 2013

@caarlos0 , I updated my blog post with a working solution for inline check boxes and radio buttons : http://stabco.tumblr.com/post/59760641051/simple-form-bootstrap3-integration

@caarlos0
Copy link

caarlos0 commented Sep 6, 2013

Nice! I'll try it later. Thank you very much!

decioferreira referenced this pull request in decioferreira/bootstrap-generators Sep 11, 2013
@andrezimpel
Copy link

Can't get it ro work with simple form 2.1.0. it says config.input_class is undefined :S

@caarlos0
Copy link

@andrezimpel try the master branch.

@andrezimpel
Copy link

@caarlos0 do i have to run a new (other) generator?

@caarlos0
Copy link

not that I can recall..

@andrezimpel
Copy link

@caarlos0 thanks, but I still get the no method error "undefined method `input_class=' for SimpleForm:Module" with the current master.

@caarlos0
Copy link

@andrezimpel did you put this in your Gemfile?

gem 'simple_form', git: 'https://github.com/plataformatec/simple_form.git'

@andrezimpel
Copy link

Naw, my fault. I just did bundle update.

Now i just have to figure out the activemodel version stuff, since I'm using rails 3.2.

Thank you very much for your help @caarlos0!

@caarlos0
Copy link

It happens 🍺

Nice to hear that. Cheers @andrezimpel

@MrHubble
Copy link

@andrezimpel Could you please report back if you figure out how to get it working with rails 3.2?

@andrezimpel
Copy link

@MrHubble Yep.

I did it this way:

  1. forked simple form (https://github.com/andrezimpel/simple_form/tree/v2.1)
  2. added that config.input_class stuff
  3. changed my simple_form_bootstrap.rb initializer (https://gist.github.com/mattclar/6315955)

I haven't ran into problems until now with that. 😃

@ghost
Copy link

ghost commented Sep 16, 2013

@andrezimpel So far so good, using your forked version w Rails4/Bootstrap3 no problem until now too... until a definitive solution is pulled out...

@mattangriffel
Copy link

@andrezimpel your initializer gave me problems because the inputs (StringInput, TextInput and others) end up conflicting with the StringInput and TextInput of Formtastic used by active_admin

@hraynaud
Copy link

@mattangriffel I'm have the same issue with conflicting simple_form/formtastic when overriding inputs. How did you resolve your issue?

@andrezimpel
Copy link

@mattangriffel I'm not using simple firm with formtastic. I take a look at in a couple of hours.

@rafaelfranca
Copy link
Collaborator

Simple Form doesn't support Bootstrap 3 yet, I'm working on it at heartcombo/simple_form-bootstrap#28.

Closing this is favor of that issue

@wtfiwtz
Copy link

wtfiwtz commented Sep 27, 2013

Here's a quick way to fix the checkbox issue whilst we wait for Rafael to implement Bootstrap3: https://github.com/wtfiwtz/simple_form_bootstrap3/commits/master

@mattangriffel
Copy link

@hraynaud I just replaced the entire top section (inputs = ... and inputs.each ...) with a simple:

SimpleForm.setup do |config|
  config.input_class = "form-control"
  ...

(which adds the form-control class to every simple_form input field)

and then constructed the checkbox manually to get around it having the form-control class when created with simple_form:

<%= f.label :remember_me, class: "checkbox" do %>
  <%= f.check_box :remember_me %> Remember me
<% end %>

@lacco
Copy link

lacco commented Nov 22, 2013

@mattangriffel : I found a solution to your problem: Instead of creating top-level objects TextInput, StringInput, I wrap those classes to a specific module and then use SimpleForm::FormBuilder.map_type to provide the mapping directly. See https://gist.github.com/adamico/6510093#comment-955517 . It's not nice, but I think simple_form should provide some mechanisms for custom inputs in a given namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet