-
Notifications
You must be signed in to change notification settings - Fork 9
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
Update docs to explain simple_form with bootstrap #11
Comments
Hmm...I still can't get it to work. Here's my code: _form.html.erb
simple_form_bootstrap
moneda.rb
I don't see any kind of client side validation. Any ideas what I'm doing wrong? |
Are you using another gem that modifies HTML attributes like ClientSideValidations? Take a look at the generated HTML, there should be a data-validate hash like that: data-validate="[{"kind":"presence","options":{},"messages":{"blank":"não pode ficar em branco"}},{"kind":"length","options":{"minimum":5},"messages":{"too_short":"é muito curto (mínimo: 5 caracteres)","blank":"não pode ficar em branco"}}]" |
Hello efmiglioranza, I do get the data-validate hash in my HTML output: data-validate="[{"kind":"presence","options":{},"messages":{"blank":"can't be blank"}},{"kind":"format","options":{"with":"(?i-mx:\A[\w+-.]+@[a-z\d-]+(.[a-z]+)*.[a-z]+\z)"},"messages":{"invalid":"is invalid","blank":"can't be blank"}}]" Yet I don't see any difference. These 2 lines: Do exactly the same, even if one has validate and the other doesn't. Thanks for the help! |
Hi Bsilvacs. if the HTML is ok, then it seems that the error is in the Javascript. Take a look at the loaded resources in your page and check if the judge.js is there (don't forget to include the files in the application.js if you are using the assets pipeline). Also, you can go to the Js console and type
If everything is ok, then there might be some error with the validations. Try to edit a field and see if there is some error in the console after the submit. About the field without the validation generating the data-validate hash, it seems that there is another gem/form builder/etc. editing your HTML and conflicting with judge. |
@efmiglioranza thx a lot for the issue post. is there anything else i should be wary about while im using judge with bootstrap and simple_form |
Yes.. I've also struggled to make it work with the prepend and append icons of bootstrap. There is a solution available where you use it withing a block, something like that: <% f.input :myfield, wrapper: :prepend do %>
<span icon tag />
<%= f.input_field :myfield %>
<% end %> But it disables the components as So I ended up using it this way: Create a new span component for simple_form: # config/initializers/simple_form/span_component.rb
module SimpleForm
module Components
module Span
def span(wrapper_options = nil)
@span ||= begin
"<span>#{options[:span]}</span>".html_safe
end
end
def has_span?
options[:span] != false && span.present?
end
end
end
end
SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Span) Configure the :prepend (and whatever you want) wrapper: # config/initializers/simple_form_bootstrap.rb
config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.use :judge
b.wrapper tag: 'div', class: 'controls' do |input|
input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :span, wrap_with: {class: 'add-on'}
prepend.use :input
end
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end Use it: <%= f.input :price, wrapper: :prepend, span: 'R$', validate: true %> Now you can use the prepend and append icons without disabling components. Hope it helps :) |
I've spent some hours trying to debug judge with simple_form and bootstrap form builder. The solution was to add
b.use :judge
at the config/initializers/simple_form_bootstrap.rb (and not the config/initializers/simple_form.rb).Example:
Using
ba.use :judge
inside the wrapper block won't work too.The text was updated successfully, but these errors were encountered: