label - Modifying the simple_form lable -
i need add span in label being generated simpleform. goal able use this coffeescript validate field presence.
currently 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 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 simple_form_bootstrap.rb
# use setup block configure options available in simpleform. simpleform.setup |config| config.wrappers :bootstrap, :tag => 'div', :class => 'control-group form-group', :error_class => 'error' |b| b.use :html5 b.use :placeholder b.use :label b.wrapper :tag => 'div', :class => 'controls' |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' |b| b.use :html5 b.use :placeholder b.use :label b.wrapper :tag => 'div', :class => 'controls' |input| input.wrapper :tag => 'div', :class => 'input-prepend' |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' |b| b.use :html5 b.use :placeholder b.use :label b.wrapper :tag => 'div', :class => 'controls' |input| input.wrapper :tag => 'div', :class => 'input-append' |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 forms , inputs using twitter bootstrap toolkit. # check bootstrap docs (http://twitter.github.com/bootstrap) # learn different styles forms , inputs, # buttons , other elements. config.default_wrapper = :bootstrap end
and here simple_form.rb
# use setup block configure options available in simpleform. simpleform.setup |config| # wrappers used form builder generate # complete input. can remove component # wrapper, change order or add own # stack. options given below used wrap # whole input. config.wrappers :default, :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors |b| ## extensions enabled default # of these extensions can disabled # given input passing: `f.input extension_name => false`. # can make of these extensions optional # renaming `b.use` `b.optional`. # determines whether use html5 (:email, :url, ...) # , required attributes b.use :html5 # calculates placeholders automatically i18n # can pass string f.input :placeholder => "placeholder" b.use :placeholder ## optional extensions # disabled unless pass `f.input extension_name => :lookup` # input. if so, retrieve values model # if exists. if want enable lookup of # extensions default, can change `b.optional` `b.use`. # calculates maxlength length validations string inputs b.optional :maxlength # calculates pattern format validations string inputs b.optional :pattern # calculates min , max length validations numeric inputs b.optional :min_max # calculates readonly automatically readonly attributes b.optional :readonly ## inputs b.use :label_input b.use :hint, :wrap_with => { :tag => :span, :class => :hint } b.use :error, :wrap_with => { :tag => :span, :class => :error } end # default wrapper used formbuilder. config.default_wrapper = :default # define way render check boxes / radio buttons labels. # defaults :nested bootstrap config. # :inline => input + label # :nested => label > input config.boolean_style = :nested # default class buttons config.button_class = 'btn' # method used tidy errors. specify rails array method. # :first lists first message each field. # use :to_sentence list errors each field. # config.error_method = :first # default tag used error notification helper. config.error_notification_tag = :div # css class add error notification helper. config.error_notification_class = 'alert alert-error' # id add error notification helper. # config.error_notification_id = nil # series of attempts detect default label method collection. # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] # series of attempts detect default value method collection. # config.collection_value_methods = [ :id, :to_s ] # can wrap collection of radio/check boxes in pre-defined tag, defaulting none. # config.collection_wrapper_tag = nil # can define class use on collection wrappers. defaulting none. # config.collection_wrapper_class = nil # can wrap each item in collection of radio/check boxes tag, # defaulting :span. please note when using :boolean_style = :nested, # simpleform force option label. # config.item_wrapper_tag = :span # can define class use in item wrappers. defaulting none. # config.item_wrapper_class = nil # how label text should generated altogether required text. # config.label_text = lambda { |label, required| "#{required} #{label}" } # can define class use on labels. default nil. config.label_class = 'control-label' # can define class use on forms. default simple_form. # config.form_class = :simple_form # can define elements should obtain additional classes # config.generate_additional_classes_for = [:wrapper, :label, :input] # whether attributes required default (or not). default true. # config.required_by_default = true # tell browsers whether use default html5 validations (novalidate option). # default enabled. config.browser_validations = false # collection of methods detect if file type given. # config.file_methods = [ :mounted_as, :file?, :public_filename ] # custom mappings input types. should hash containing regexp # match key, , input type used when field name # matches regexp value. # config.input_mappings = { /count/ => :integer } # custom wrappers input types. should hash containing input # type key , wrapper used inputs specified type. # config.wrapper_mappings = { :string => :prepend } # default priority time_zone inputs. # config.time_zone_priority = nil # default priority country inputs. # config.country_priority = ["pakistan"] # default size text inputs. # config.default_input_size = 50 # when false, not use translations labels. # config.translate_labels = true # automatically discover new inputs in rails' autoload path. # config.inputs_discovery = true # cache simpleform inputs discovery # config.cache_discovery = !rails.env.development? end
Comments
Post a Comment