Module: Tennpipes::Helpers::FormHelpers

Defined in:
lib/tennpipes-helper/form_helpers.rb,
lib/tennpipes-helper/form_helpers/errors.rb,
lib/tennpipes-helper/form_helpers/options.rb,
lib/tennpipes-helper/form_helpers/security.rb

Overview

Helpers related to producing form related tags and inputs into templates.

Defined Under Namespace

Modules: Errors, Options, Security

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
15
# File 'lib/tennpipes-helper/form_helpers.rb', line 11

def self.included(base)
  base.send(:include, FormHelpers::Errors)
  base.send(:include, FormHelpers::Options)
  base.send(:include, FormHelpers::Security)
end

Instance Method Details

#button_tag(caption, options = {}) ⇒ String

Constructs a button input from the given options.

Examples:

button_tag "Cancel", :class => 'clear'

Parameters:

  • caption (String)

    The caption for the button.

  • options (Hash) (defaults to: {})

    The html options for the input field.

Returns:

  • (String)

    The html button based on the options specified.



509
510
511
# File 'lib/tennpipes-helper/form_helpers.rb', line 509

def button_tag(caption, options = {})
  input_tag(:button, { :value => caption }.update(options))
end

#button_to(caption, url, options = {}) ⇒ String #button_to(url, options = {}, &block) ⇒ String

Creates a form containing a single button that submits to the URL.

Examples:

button_to 'Delete', url(:accounts_destroy, :id => ), :method => :delete, :class => :form
# Generates:
# <form class="form" action="/admin/accounts/destroy/2" method="post">
#   <input type="hidden" value="delete" name="_method" />
#   <input type="submit" value="Delete" />
# </form>

Overloads:

  • #button_to(caption, url, options = {}) ⇒ String

    Parameters:

    • caption (String)

      The text caption.

    • url (String)

      The url href.

    • options (Hash) (defaults to: {})

      The html options.

  • #button_to(url, options = {}, &block) ⇒ String

    Parameters:

    • url (String)

      The url href.

    • options (Hash) (defaults to: {})

      The html options.

    • block (Proc)

      The button content.

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (String)

    Form and button html with specified options.



582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/tennpipes-helper/form_helpers.rb', line 582

def button_to(*args, &block)
  options   = args.extract_options!.dup
  name, url = *args
  options['data-remote'] = 'true' if options.delete(:remote)
  submit_options = options.delete(:submit_options) || {}
  form_tag(url || name, options) do
    if block_given?
      (:button, capture_html(&block), submit_options)
    else
      submit_tag(name, submit_options)
    end
  end
end

#check_box_tag(name, options = {}) ⇒ Object

Constructs a check_box from the given options.

Examples:

check_box_tag :remember_me, :value => 'Yes'


422
423
424
# File 'lib/tennpipes-helper/form_helpers.rb', line 422

def check_box_tag(name, options={})
  input_tag(:checkbox, { :name => name, :value => '1' }.update(options))
end

#email_field_tag(name, options = {}) ⇒ String

Creates an email field input with the given name and options.

Examples:

email_field_tag :email, :placeholder => '[email protected]'
# => <input name="email" placeholder="[email protected]" type="email" />

email_field_tag :email, :value => '[email protected]', :readonly => true
# => <input name="email" value="[email protected]" readonly type="email" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :maxlength (Integer)

    Specifies the maximum length, in characters, of the field.

  • :size (Integer)

    Specifies the width, in characters, of the field.

  • :placeholder (String)

    Specifies a short hint that describes the expected value of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completed before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



341
342
343
# File 'lib/tennpipes-helper/form_helpers.rb', line 341

def email_field_tag(name, options={})
  input_tag(:email, { :name => name }.update(options))
end

#field_set_tag(legend = nil, options = {}, &block) ⇒ String #field_set_tag(options = {}, &block) ⇒ String

Constructs a field_set to group fields with given options.

Examples:

field_set_tag(:class => "office-set") { }
field_set_tag("Office", :class => 'office-set') { }

Overloads:

  • #field_set_tag(legend = nil, options = {}, &block) ⇒ String

    Parameters:

    • legend (String) (defaults to: nil)

      The legend caption for the fieldset

    • options (Hash) (defaults to: {})

      The html options for the fieldset.

    • block (Proc)

      The content inside the fieldset.

  • #field_set_tag(options = {}, &block) ⇒ String

    Parameters:

    • options (Hash) (defaults to: {})

      The html options for the fieldset.

    • block (Proc)

      The content inside the fieldset.

Returns:

  • (String)

    The html for the fieldset tag based on given options.



145
146
147
148
149
150
# File 'lib/tennpipes-helper/form_helpers.rb', line 145

def field_set_tag(*args, &block)
  options = args.extract_options!
  legend_text = args.first
  legend_html = legend_text.blank? ? ActiveSupport::SafeBuffer.new : (:legend, legend_text)
  concat_content (:fieldset, legend_html << capture_html(&block), options)
end

#fields_for(object, options = {}, &block) ⇒ String

Constructs form fields for an object using given or default form_builder. Used within an existing form to allow alternate objects within one form.

Examples:

fields_for @user.assignment do |assignment| ... end
fields_for :assignment do |assigment| ... end

Parameters:

  • object (Object)

    The object for which the fields are being built.

  • options (Hash) (defaults to: {})

    The settings associated with these fields. Accepts HTML options.

  • block (Proc)

    The content inside this set of fields.

Returns:

  • (String)

    The html fields with the specified options.



69
70
71
72
73
74
# File 'lib/tennpipes-helper/form_helpers.rb', line 69

def fields_for(object, options={}, &block)
  instance = builder_instance(object, options)
  fields_html = capture_html(instance, &block)
  fields_html << instance.hidden_field(:id) if instance.send(:nested_object_id)
  concat_content fields_html
end

#file_field_tag(name, options = {}) ⇒ Object

Constructs a file field input from the given options.

Examples:

file_field_tag :photo, :class => 'long'


443
444
445
446
# File 'lib/tennpipes-helper/form_helpers.rb', line 443

def file_field_tag(name, options={})
  name = "#{name}[]" if options[:multiple]
  input_tag(:file, { :name => name }.update(options))
end

#form_for(object, url, options = {}, &block) {|AbstractFormBuilder| ... } ⇒ String

Constructs a form for object using given or default form_builder.

Examples:

form_for :user, '/register' do |f| ... end
form_for @user, '/register', :id => 'register' do |f| ... end
form_for @user, '/register', :as => :customer do |f| ... end

Parameters:

  • object (Object)

    The object for which the form is being built.

  • URL (String)

    The url this form will submit to.

  • options (Hash) (defaults to: {})

    The settings associated with this form. Accepts a :namespace option that will be prepended to the id attributes of the form’s elements. Also accepts HTML options.

  • block (Proc)

    The fields and content inside this form.

  • settings (Hash)

    a customizable set of options

Yields:

  • (AbstractFormBuilder)

    The form builder used to compose fields.

Returns:

  • (String)

    The html object-backed form with the specified options and input fields.



44
45
46
47
48
49
50
# File 'lib/tennpipes-helper/form_helpers.rb', line 44

def form_for(object, url, options={}, &block)
  instance = builder_instance(object, options)
  # this can erect instance.multipart flag if the block calls instance.file_field
  html = capture_html(instance, &block)
  options = { :multipart => instance.multipart }.update(options.except(:namespace, :as))
  form_tag(url, options) { html }
end

#form_tag(url, options = {}, &block) ⇒ String

Constructs a form without object based on options.

Examples:

form_tag '/register', :class => "registration_form" do ... end

Parameters:

  • url (String)

    The URL this form will submit to.

  • options (Hash) (defaults to: {})

    The html options associated with this form.

  • block (Proc)

    The fields and content inside this form.

Returns:

  • (String)

    The HTML form with the specified options and input fields.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/tennpipes-helper/form_helpers.rb', line 91

def form_tag(url, options={}, &block)
  options = {
    :action => url,
    :protect_from_csrf => is_protected_from_csrf?,
    'accept-charset' => 'UTF-8'
  }.update(options)
  options[:enctype] = 'multipart/form-data' if options.delete(:multipart)

  if (desired_method = options[:method]) =~ /get/i
    options.delete(:protect_from_csrf)
  else
    options[:method] = 'post'
  end
  inner_form_html = hidden_form_method_field(desired_method)
  inner_form_html << csrf_token_field if options.delete(:protect_from_csrf)
  concat_content (:form, inner_form_html << capture_html(&block), options)
end

#hidden_field_tag(name, options = {}) ⇒ Object

Constructs a hidden field input from the given options.

Examples:

hidden_field_tag :session_key, :value => "__secret__"


389
390
391
# File 'lib/tennpipes-helper/form_helpers.rb', line 389

def hidden_field_tag(name, options={})
  input_tag(:hidden, { :name => name }.update(options))
end

#hidden_form_method_field(desired_method) ⇒ String

Returns the hidden method field for ‘put’ and ‘delete’ forms. Only ‘get’ and ‘post’ are allowed within browsers; ‘put’ and ‘delete’ are just specified using hidden fields with form action still ‘put’.

Examples:

# Generate: <input name="_method" value="delete" />
hidden_form_method_field('delete')

Parameters:

  • desired_method (String)

    The method this hidden field represents (i.e put or delete).

Returns:

  • (String)

    The hidden field representing the desired_method for the form.



123
124
125
126
# File 'lib/tennpipes-helper/form_helpers.rb', line 123

def hidden_form_method_field(desired_method)
  return ActiveSupport::SafeBuffer.new if desired_method.blank? || desired_method.to_s =~ /get|post/i
  hidden_field_tag(:_method, :value => desired_method)
end

#image_submit_tag(source, options = {}) ⇒ String

Constructs a submit button from the given options.

Examples:

image_submit_tag 'form/submit.png'

Parameters:

  • source (String)

    The source image path for the button.

  • options (Hash) (defaults to: {})

    The html options for the input field.

Returns:

  • (String)

    The html image button based on the options specified.



547
548
549
# File 'lib/tennpipes-helper/form_helpers.rb', line 547

def image_submit_tag(source, options={})
  input_tag(:image, { :src => image_path(source) }.update(options))
end

#label_tag(name, options = {}, &block) ⇒ String

Constructs a label tag from the given options.

Examples:

label_tag :username, :class => 'long-label'
label_tag :username, :class => 'long-label' do ... end

Parameters:

  • name (String)

    The name of the field to label.

  • options (Hash) (defaults to: {})

    The html options for this label.

  • block (Proc)

    The content to be inserted into the label.

Options Hash (options):

  • :caption (Object)

    The caption for this label.

Returns:

  • (String)

    The html for this label with the given options.



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/tennpipes-helper/form_helpers.rb', line 170

def label_tag(name, options={}, &block)
  options = { :caption => "#{name.to_s.humanize}: ", :for => name }.update(options)
  caption_text = ActiveSupport::SafeBuffer.new << options.delete(:caption)
  caption_text << "<span class='required'>*</span> ".html_safe if options.delete(:required)

  if block_given?
    concat_content (:label, caption_text << capture_html(&block), options)
  else
    (:label, caption_text, options)
  end
end

#number_field_tag(name, options = {}) ⇒ String

Creates a number field input with the given name and options.

Examples:

number_field_tag :quantity, :class => 'numeric'
# => <input name="quantity" class="numeric" type="number" />

number_field_tag :zip_code, :pattern => /[0-9]{5}/
# => <input name="zip_code" pattern="[0-9]{5}" type="number" />

number_field_tag :credit_card, :autocomplete => :off
# => <input name="credit_card" autocomplete="off" type="number" />

number_field_tag :age, :min => 18, :max => 120, :step => 1
# => <input name="age" min="18" max="120" step="1" type="number" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :min (Integer)

    Specifies the minimum value of the field.

  • :max (Integer)

    Specifies the maximum value of the field.

  • :step (Integer)

    Specifies the legal number intervals of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completeled before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



303
304
305
# File 'lib/tennpipes-helper/form_helpers.rb', line 303

def number_field_tag(name, options={})
  input_tag(:number, { :name => name }.update(options))
end

#password_field_tag(name, options = {}) ⇒ Object

Constructs a password field input from the given options.

Examples:

password_field_tag :password, :class => 'long'


412
413
414
# File 'lib/tennpipes-helper/form_helpers.rb', line 412

def password_field_tag(name, options={})
  input_tag(:password, { :name => name }.update(options))
end

#radio_button_tag(name, options = {}) ⇒ Object

Constructs a radio_button from the given options.

Examples:

radio_button_tag :remember_me, :value => 'true'


432
433
434
# File 'lib/tennpipes-helper/form_helpers.rb', line 432

def radio_button_tag(name, options={})
  input_tag(:radio, { :name => name }.update(options))
end

#range_field_tag(name, options = {}) ⇒ String

Constructs a range tag from the given options.

Examples:

range_field_tag('ranger_with_min_max', :min => 1, :max => 50)
range_field_tag('ranger_with_range', :range => 1..5)

Parameters:

  • name (String)

    The name of the range field.

  • options (Hash) (defaults to: {})

    The html options for the range field.

Options Hash (options):

  • :min (Integer)

    The min range of the range field.

  • :max (Integer)

    The max range of the range field.

  • :range (range)

    The range, in lieu of :min and :max. See examples for details.

Returns:

  • (String)

    The html range field



615
616
617
618
619
620
621
# File 'lib/tennpipes-helper/form_helpers.rb', line 615

def range_field_tag(name, options = {})
  options = { :name => name }.update(options)
  if range = options.delete(:range)
    options[:min], options[:max] = range.min, range.max
  end
  input_tag(:range, options)
end

#search_field_tag(name, options = {}) ⇒ String

Creates a search field input with the given name and options.

Examples:

search_field_tag :search, :placeholder => 'Search this website...'
# => <input name="search" placeholder="Search this website..." type="search" />

search_field_tag :search, :maxlength => 15, :class => ['search', 'string']
# => <input name="search" maxlength="15" class="search string" />

search_field_tag :search, :id => 'search'
# => <input name="search" id="search" type="search" />

search_field_tag :search, :autofocus => true
# => <input name="search" autofocus type="search" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :maxlength (Integer)

    Specifies the maximum length, in characters, of the field.

  • :size (Integer)

    Specifies the width, in characters, of the field.

  • :placeholder (String)

    Specifies a short hint that describes the expected value of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completed before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



363
364
365
# File 'lib/tennpipes-helper/form_helpers.rb', line 363

def search_field_tag(name, options={})
  input_tag(:search, { :name => name }.update(options))
end

#select_tag(name, options = {}) ⇒ String

Constructs a select from the given options.

Examples:

options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
options = ['option', 'red', 'yellow' ]
select_tag(:favorite_color, :options => ['red', 'yellow'], :selected => 'green1')
select_tag(:country, :collection => @countries, :fields => [:name, :code], :include_blank => 'None')

# Optgroups can be generated using :grouped_options => (Hash or nested Array)
grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])

# Optgroups can be generated using the rails-style attribute hash.
grouped_options = {
  "Friends" => ["Yoda", ["Obiwan", 2, {:magister => 'no'}], {:lame => 'yes'}],
  "Enemies" => [["Palpatine", "Palpatine", {:scary => 'yes', :old => 'yes'}], ["Darth Vader", 3, {:disabled => true}]]
}
select_tag(:name, :grouped_options => grouped_options)

Parameters:

  • name (String)

    The name of the input field.

  • options (Hash) (defaults to: {})

    The html options for the input field.

Options Hash (options):

  • :options (Array<String, Array>)

    Explicit options to display in the select. Can be strings or string tuples.

  • :grouped_options (Array<Array>)

    List of options for each group in the select. See examples for details.

  • :collection (Array<Object>)

    Collection of objects used as options in the select.

  • :fields (Array<Symbol>)

    The attributes used as “label” and “value” for each collection object.

  • :selected (String) — default: nil

    The option value initially selected.

  • :include_blank (Boolean) — default: false

    Include a blank option in the select.

  • :multiple (Boolean) — default: false

    Allow multiple options to be selected at once.

Returns:

  • (String)

    The HTML input field based on the options specified.



490
491
492
493
494
# File 'lib/tennpipes-helper/form_helpers.rb', line 490

def select_tag(name, options={})
  options = { :name => name }.merge(options)
  options[:name] = "#{options[:name]}[]" if options[:multiple]
  (:select, extract_option_tags!(options), options)
end

#submit_tag(options = {}) ⇒ String #submit_tag(caption, options = {}) ⇒ String

Constructs a submit button from the given options.

Examples:

submit_tag "Create", :class => 'success'
submit_tag :class => 'btn'

Overloads:

  • #submit_tag(options = {}) ⇒ String

    Parameters:

    • options (Hash) (defaults to: {})

      The html options for the input field.

  • #submit_tag(caption, options = {}) ⇒ String

    Parameters:

    • caption (String)

      The caption for the submit button.

    • options (Hash) (defaults to: {})

      The html options for the input field.

Returns:

  • (String)

    The html submit button based on the options specified.



528
529
530
531
532
# File 'lib/tennpipes-helper/form_helpers.rb', line 528

def submit_tag(*args)
  options = args.extract_options!
  caption = args.length >= 1 ? args.first : "Submit"
  input_tag(:submit, { :value => caption }.merge(options))
end

#telephone_field_tag(name, options = {}) ⇒ String Also known as: phone_field_tag

Creates a telephone field input with the given name and options.

telephone_field_tag :cell_phone, :tabindex => 1
telephone_field_tag :work_phone, :tabindex => 2
telephone_field_tag :home_phone, :tabindex => 3

# => <input name="cell_phone" tabindex="1" type="tel" />
# => <input name="work_phone" tabindex="2" type="tel" />
# => <input name="home_phone" tabindex="3" type="tel" />

Examples:

telephone_field_tag :phone_number, :class => 'string'
# => <input name="phone_number" class="string" type="tel" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :maxlength (Integer)

    Specifies the maximum length, in characters, of the field.

  • :size (Integer)

    Specifies the width, in characters, of the field.

  • :placeholder (String)

    Specifies a short hint that describes the expected value of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completed before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



324
325
326
# File 'lib/tennpipes-helper/form_helpers.rb', line 324

def telephone_field_tag(name, options={})
  input_tag(:tel, { :name => name }.update(options))
end

#text_area_tag(name, options = {}) ⇒ Object

Constructs a text area input from the given options.

Examples:

text_area_tag :username, :class => 'long', :value => "Demo?"


399
400
401
402
403
# File 'lib/tennpipes-helper/form_helpers.rb', line 399

def text_area_tag(name, options={})
  inner_html = TagHelpers::NEWLINE + options.delete(:value).to_s
  options = { :name => name, :rows => "", :cols => "" }.update(options)
  (:textarea, inner_html, options)
end

#text_field_tag(name, options = {}) ⇒ String

Creates a text field input with the given name and options.

Examples:

text_field_tag :first_name, :maxlength => 40, :required => true
# => <input name="first_name" maxlength="40" required type="text" />

text_field_tag :last_name, :class => 'string', :size => 40
# => <input name="last_name" class="string" size="40" type="text" />

text_field_tag :username, :placeholder => 'Your Username'
# => <input name="username" placeholder="Your Username" type="text" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :maxlength (Integer)

    Specifies the maximum length, in characters, of the field.

  • :size (Integer)

    Specifies the width, in characters, of the field.

  • :placeholder (String)

    Specifies a short hint that describes the expected value of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completed before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



239
240
241
# File 'lib/tennpipes-helper/form_helpers.rb', line 239

def text_field_tag(name, options={})
  input_tag(:text, { :name => name }.update(options))
end

#url_field_tag(name, options = {}) ⇒ String

Creates a URL field input with the given name and options.

Examples:

url_field_tag :favorite_website, :placeholder => 'http://tennpipesrb.com'
<input name="favorite_website" placeholder="http://tennpipesrb.com." type="url" />

url_field_tag :home_page, :class => 'string url'
<input name="home_page" class="string url", type="url" />

Parameters:

  • name (Symbol)

    The name of the input to create.

  • options (Hash) (defaults to: {})

    The HTML options to include in this field.

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the field.

  • :class (String)

    Specifies the stylesheet class of the field.

  • :name (String)

    Specifies the name of the field.

  • :accesskey (String)

    Specifies a shortcut key to access the field.

  • :tabindex (Integer)

    Specifies the tab order of the field.

  • :maxlength (Integer)

    Specifies the maximum length, in characters, of the field.

  • :size (Integer)

    Specifies the width, in characters, of the field.

  • :placeholder (String)

    Specifies a short hint that describes the expected value of the field.

  • :hidden (Boolean)

    Specifies whether or not the field is hidden from view.

  • :spellcheck (Boolean)

    Specifies whether or not the field should have it’s spelling and grammar checked for errors.

  • :draggable (Boolean)

    Specifies whether or not the field is draggable. (true, false, :auto).

  • :pattern (String)

    Specifies the regular expression pattern that the field’s value is checked against.

  • :autocomplete (Symbol)

    Specifies whether or not the field should have autocomplete enabled. (:on, :off).

  • :autofocus (Boolean)

    Specifies whether or not the field should automatically get focus when the page loads.

  • :required (Boolean)

    Specifies whether or not the field is required to be completed before the form is submitted.

  • :readonly (Boolean)

    Specifies whether or not the field is read only.

  • :disabled (Boolean)

    Specifies whether or not the field is disabled.

Returns:

  • (String)

    Generated HTML with specified options.



379
380
381
# File 'lib/tennpipes-helper/form_helpers.rb', line 379

def url_field_tag(name, options={})
  input_tag(:url, { :name => name }.update(options))
end