Module: ActionView::Helpers::FormTagHelper
- Defined in:
- lib/calendariffic/action_view.rb
Instance Method Summary collapse
- #calendar_tag(name, value = Date.current, *args) ⇒ Object
-
#calendariffic_input(calendar_is_before_text, text_name, image_source, image_name, date_format, text_value, text_attributes = {}, image_attributes = {}) ⇒ Object
Creates a DHTML pop-up calendar icon and an associated text-box to display the selected date.
-
#current_date ⇒ Object
Uses Date.current to be more accurate for Rails applications.
Instance Method Details
#calendar_tag(name, value = Date.current, *args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/calendariffic/action_view.rb', line 4 def calendar_tag(name, value = Date.current, *args) = args. date_format = '%d-%m-%Y' value = value.strftime(date_format) if value.respond_to?(:day) name = name.to_s if name.is_a?(Symbol) [:id] = [:id] || name.gsub(/\]$/, '').gsub(/\]\[/, '[').gsub(/[\[\]]/, '_') [:size] ||= 10 [:maxlength] ||= 10 [:class] ||= '' [:class] += ' calendar_text' [:class] += ' warn_in_past' if [:warn_in_past] calendariffic_input(false, name, 'calendariffic/date.png', "#{[:id]}_img", date_format, value, , {}).html_safe end |
#calendariffic_input(calendar_is_before_text, text_name, image_source, image_name, date_format, text_value, text_attributes = {}, image_attributes = {}) ⇒ Object
Creates a DHTML pop-up calendar icon and an associated text-box to display the selected date.
calendar_is_before_text: boolean to determine whether the calendar icon is placed before or after the text-box
e.g. true will produce <img ... /><input type="text" ... /> whereas false will generate <input type="text" ... /><img ... />
text_name: specifies the name and id attributes of the text-box. The user MUST specify this value and it MUST be different from the value specified in image_name. image_source: relative path specifying the location of an icon to represent the pop-up calendar.
Several calendar icons are located in public/images/calendariffic
image_name: the name and id you want associated with your calendar icon. The user MUST specify this value and it MUST be different from the value specified in text_name. date_format: the format in which the date will appear within the text_box. See table below for valid abbreviations for date.
a date_format of nil will default to mm/dd/yy.
text_value: the initial value you want to show up within the text box (e.g. ‘07/04/2007’)
if the user passes the string 'today' the text_value will initially display today's date in whichever format is specified by the date_format parameter.
the 'today' string is case-insensitive.
text_attributes: any other attributes that can be placed into an <input type=“text” /> HTML element can be placed here within a Hash. e.g. => ‘myfavoriteclass’ image_attributes: any other attributes that can be placed into an <img src=“” … /> HTML element can be placed here within a Hash. e.g. => ‘cal’
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/calendariffic/action_view.rb', line 43 def calendariffic_input(calendar_is_before_text, text_name, image_source, image_name, date_format, text_value, text_attributes={}, image_attributes={}) text_attributes[:id] ||= text_name image_attributes[:name] = image_name if image_name image_attributes[:id] = image_name if image_name date_format = '%d-%m-%Y' if date_format.nil? text_value ||= current_date.strftime(date_format) imt = image_tag image_source, image_attributes tft = text_field_tag(text_name, text_value, text_attributes) script = "<script language='javascript'>set_cal('#{text_attributes[:id]}', '#{image_name}', '#{date_format}');</script>" calendar_is_before_text ? "#{imt}#{tft}#{script}" : "#{tft}#{imt}#{script}" end |
#current_date ⇒ Object
Uses Date.current to be more accurate for Rails applications
23 24 25 |
# File 'lib/calendariffic/action_view.rb', line 23 def current_date Date.respond_to?(:current) ? Date.current : Date.today end |