Hobo Cookbook

View Source

Rapid

<input>

Provides an editable control tailored to the type of the object in context. <input> tags should be used within a <form>. <input> is a polymorphic tag which means that there are a variety of definitions, each one written for a particular type. For example there are inputs for text, boolean, password, date, datetime, integer, float, string and more.

Usage

The tag behaves as a regular HTML input if the type attribute is given:

<input type="text" name="my_input"/> -> Output is exactly as provided, untouched by Rapid

If no type attribute is given then the context is used. For example if the context is a blog post:

<input:title/> ->
<input id="blog_post[name]" class="string blog-post-name" type="text" value="My Blog Post" name="blog_post[name]"/>

<input:created_at/> ->
<select id="blog_post_created_at_year" name="blog_post[created_at][year]">...</select>
<select id="blog_post_created_at_month" name="blog_post[created_at][month]">...</select>
<select id="blog_post_created_at_day" name="blog_post[created_at][day]">...</select>

<input:description/> ->
<textarea class="text blog-post-description" id="blog_post[description]" name="blog_post[description]">...</textarea>

If the context is a belongs_to association, the <select-one> tag is used.

If the context is a has_many :through association, the polymorphic <collection-input> tag is used.

Attributes

  • no-edit: control what happens if can_edit? is false. Can be one of:

    • view: render the current value using the <view> tag
    • disable: render the input as normal, but add HTML’s disabled attribute
    • skip: render nothing at all
    • ignore: render the input normally. That is, don’t even perform the edit check.

Show Source

<input for='HoboFields::EnumString'>

A <select> menu containing the values of an ‘enum string’.

Attributes

  • labels - A hash that gives custom labels for the values of the enum. Any values that do not have corresponding keys in this hash will get value.titleize as the label.
  • titleize - Set to false to have the value itself (rather than value.titleize) be the default label. Default: true
  • first-option - a string to be used for an extra option in the first position. E.g. “Please choose…”
  • first-value - the value to be used with the first-option. Typically not used, meaning the option has a blank value.

Show Source

<input for='text'>

A <textarea> input

Show Source

<input for='boolean'>

A checkbox plus a hidden-field. The hidden field trick comes from Rails - it means that when the checkbox is not checked, the parameter name is still submitted, with a ‘0’ value (the value is ‘1’ when the checkbox is checked)

Show Source

<input for='password'>

A password input - <input type='password'>

Show Source

<input for='date'>

A date picker, using the select_date helper from Rails

Attributes

  • all the options of select_date and date_select are passed to the select_date Rails helper

All the other attributes are passed to the select_date helper as the html-options hash.

The menus default to the current date if the current value is nil.

Examples:

- override the input for date tag in a form

 <my-special-date-view:>
    <input start-year="&1940" order="day,month,year" />
 </my-special-date-view:>

- override the tag application-wide

 <extend tag='input' for='date'>
   <old-input merge order="day,month,year" start-year="&1940" />
 </extend>

Show Source

<input for='time'>

A date/time picker, using the select_time helper from Rails

Attributes

  • include-seconds, time-separator, prompt and prefix are passed to the select_time helper as options

All the other attributes are passed to the select_time helper as the html-options hash.

The menus default to the current time if the current value is nil.

Show Source

<input for='datetime'>

A date/time picker, using the select_datetime helper from Rails

Attributes

  • order: The order of the year, month and date menus. A comma separated string or an array. Default: “year, month, day, hour, minute”
  • date-separator, discard-type, prompt and prefix are passed to the select_date helper as options

All the other attributes are passed to the select_date helper as the html-options hash.

The menus default to the current time if the current value is nil.

Show Source

<input for='integer'>

An <input type='text'> input.

Show Source

<input for='float'>

An <input type='text'> input.

Show Source

<input for='string'>

An <input type='text'> input.

Show Source

<input for='big_integer'>

An <input type='text'> input.

Show Source

<input for='Paperclip::Attachment'>

Show Source

<input for='BigDecimal'>

An <input type='text'> input.

Show Source

<input for='HoboFields::Types::EnumString'>

A <select> menu containing the values of an ‘enum string’.

Attributes

  • labels - A hash that gives custom labels for the values of the enum. Any values that do not have corresponding keys in this hash will get value.titleize as the label.
  • titleize - Set to false to have the value itself (rather than value.titleize) be the default label. Default: true
  • first-option - a string to be used for an extra option in the first position. E.g. “Please choose…”
  • first-value - the value to be used with the first-option. Typically not used, meaning the option has a blank value.

Show Source

Comments

No Comments to display