help is resolving validation issue

30 views
Skip to first unread message

QAISER MUHAMMAD

unread,
Sep 29, 2014, 12:58:27 PM9/29/14
to plataformate...@googlegroups.com
I am trying to use coffeescript to resolve an issue with validations and am following this github page. I ran across an issue and created a SO question more than a month ago with no answer yet.

here is my question. http://stackoverflow.com/questions/25359973/modifying-the-simple-form-lable. I have copied the whole question below. Please assist me in solving this problem.



I need to add an extra span in the label being generated by SimpleForm. The goal is to be able to use this coffeescript to validate field presence.

Currently it looks like:

<div class="control-group form-group string optional dealer_website">
  <label class="string optional control-label" for="dealer_website">
    Website
  </label>
  <div class="controls">
    <input class="string optional form-control" id="dealer_website" name="dealer[website]" size="50" type="text">
  </div>
</div>

I need it to look like:

<div class="control-group form-group string optional dealer_website">
  <label class="string optional control-label" for="dealer_website">
    Website
    <span class="error-message"></span>
  </label>
  <div class="controls">
    <input class="string optional form-control" id="dealer_website" name="dealer[website]" size="50" type="text">
  </div>
</div>

here is my simple_form_bootstrap.rb

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|

  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group form-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

  config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
        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

  config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-append' do |append|
        append.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

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap
end

and here is the simple_form.rb

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  # Wrappers are used by the form builder to generate a
  # complete input. You can remove any component from the
  # wrapper, change the order or even add your own to the
  # stack. The options given below are used to wrap the
  # whole input.
  config.wrappers :default, :class => :input,
    :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|

    ## Extensions enabled by default
    # Any of these extensions can be disabled for a
    # given input by passing: `f.input EXTENSION_NAME => false`.
    # You can make any of these extensions optional by
    # renaming `b.use` to `b.optional`.

    # Determines whether to use HTML5 (:email, :url, ...)
    # and required attributes
    b.use :html5

    # Calculates placeholders automatically from I18n
    # You can also pass a string as f.input :placeholder => "Placeholder"
    b.use :placeholder

    ## Optional extensions
    # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
    # to the input. If so, they will retrieve the values from the model
    # if any exists. If you want to enable the lookup for any of those
    # extensions by default, you can change `b.optional` to `b.use`.

    # Calculates maxlength from length validations for string inputs
    b.optional :maxlength

    # Calculates pattern from format validations for string inputs
    b.optional :pattern

Carlos Antonio da Silva

unread,
Sep 29, 2014, 11:33:09 PM9/29/14
to plataformate...@googlegroups.com
You should probably use a custom input that is able to append the error into the label, I believe there're examples on how to do that on the wiki. Hope that helps.

--
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
Reply all
Reply to author
Forward
0 new messages