How to hiding hint if has error in input field

173 views
Skip to first unread message

Joseh-Henrique Caetano de Brito e Silva

unread,
Jul 24, 2014, 1:28:15 PM7/24/14
to plataformate...@googlegroups.com
gem 'rails', '4.0.8'
gem 'simple_form', '~> 3.1.0.rc1', github: 'plataformatec/simple_form', branch: 'master'
gem 'bootstrap-sass', '3.1.1'

View code
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  b
.use :html5
  b
.use :placeholder
  b
.optional :maxlength
  b
.optional :pattern
  b
.optional :min_max
  b
.optional :readonly
  b
.use :label, class: 'col-sm-2 control-label'

  b
.wrapper tag: 'div', class: 'col-sm-10' do |ba|
    ba
.use :input, class: 'form-control'
    ba
.use :error, wrap_with: { tag: 'span', class: 'help-block' }
## how change this
    ba
.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
## to if has error
    ba
.use :hint,  wrap_with: { tag: 'p', class: 'help-block-hidden', style: 'display: none;' }
 
end
end

Example source code to be generated:

Before error - Show hint:
<p class="help-block">Login de acesso ao sistema</p>

During error - Hide hint
<p style="display: none;" class="help-block-hidden">Login de acesso ao sistema</p>



Must exist other ways, but would like the SimpleForm

Carlos Antonio da Silva

unread,
Jul 24, 2014, 6:33:48 PM7/24/14
to plataformate...@googlegroups.com
There's no specific support for that in Simple Form, you'd have to monkeypatch the Hints module and add a check on has_errors? on something like that.



--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

David Susco

unread,
Aug 30, 2018, 9:29:24 AM8/30/18
to SimpleForm
Four years late, but in case anyone else is looking to do this...

I changed the order of the hint and error in `config/initializers/simple_form.rb`:

    b.use :label_input
    b.use :full_error, wrap_with: { tag: :span, class: :error }
    b.use :hint,  wrap_with: { tag: :span, class: :hint }

Then you can hide `span.hint` with a CSS rule on `span.error`.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simpleform+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages