Skip to content

Commit e2ef1d6

Browse files
authored
Merge pull request rails#50828 from akhilgkrishnan/add-example-for-month-field-tag
Add examples for form helper tags [ci skip]
2 parents e46e56b + 5c6dcda commit e2ef1d6

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

actionview/lib/action_view/helpers/form_tag_helper.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,23 @@ def date_field_tag(name, value = nil, options = {})
747747
# * <tt>:max</tt> - The maximum acceptable value.
748748
# * <tt>:step</tt> - The acceptable value granularity.
749749
# * <tt>:include_seconds</tt> - Include seconds and ms in the output timestamp format (true by default).
750+
#
751+
# ==== Examples
752+
#
753+
# time_field_tag 'name'
754+
# # => <input id="name" name="name" type="time" />
755+
#
756+
# time_field_tag 'time', '01:01'
757+
# # => <input id="time" name="time" type="time" value="01:01" />
758+
#
759+
# time_field_tag 'time', nil, class: 'special_input'
760+
# # => <input class="special_input" id="time" name="time" type="time" />
761+
#
762+
# time_field_tag 'time', '01:01', include_seconds: true
763+
# # => <input id="time" name="time" type="time" value="01:01:00.000" />
764+
#
765+
# time_field_tag 'time', '01:01', min: '00:00', max: '23:59', step: 1
766+
# # => <input id="time" max="23:59" min="00:00" name="time" step="1" type="time" value="01:01" />
750767
def time_field_tag(name, value = nil, options = {})
751768
text_field_tag(name, value, options.merge(type: :time))
752769
end
@@ -761,6 +778,20 @@ def time_field_tag(name, value = nil, options = {})
761778
# * <tt>:max</tt> - The maximum acceptable value.
762779
# * <tt>:step</tt> - The acceptable value granularity.
763780
# * <tt>:include_seconds</tt> - Include seconds in the output timestamp format (true by default).
781+
#
782+
# ==== Examples
783+
#
784+
# datetime_field_tag 'name'
785+
# # => <input id="name" name="name" type="datetime-local" />
786+
#
787+
# datetime_field_tag 'datetime', '2014-01-01T01:01'
788+
# # => <input id="datetime" name="datetime" type="datetime-local" value="2014-01-01T01:01" />
789+
#
790+
# datetime_field_tag 'datetime', nil, class: 'special_input'
791+
# # => <input class="special_input" id="datetime" name="datetime" type="datetime-local" />
792+
#
793+
# datetime_field_tag 'datetime', '2014-01-01T01:01', class: 'special_input', disabled: true
794+
# # => <input disabled="disabled" class="special_input" id="datetime" name="datetime" type="datetime-local" value="2014-01-01T01:01" />
764795
def datetime_field_tag(name, value = nil, options = {})
765796
text_field_tag(name, value, options.merge(type: "datetime-local"))
766797
end
@@ -776,6 +807,20 @@ def datetime_field_tag(name, value = nil, options = {})
776807
# * <tt>:min</tt> - The minimum acceptable value.
777808
# * <tt>:max</tt> - The maximum acceptable value.
778809
# * <tt>:step</tt> - The acceptable value granularity.
810+
#
811+
# ==== Examples
812+
#
813+
# month_field_tag 'name'
814+
# # => <input id="name" name="name" type="month" />
815+
#
816+
# month_field_tag 'month', '2014-01'
817+
# # => <input id="month" name="month" type="month" value="2014-01" />
818+
#
819+
# month_field_tag 'month', nil, class: 'special_input'
820+
# # => <input class="special_input" id="month" name="month" type="month" />
821+
#
822+
# month_field_tag 'month', '2014-01', class: 'special_input', disabled: true
823+
# # => <input disabled="disabled" class="special_input" id="month" name="month" type="month" value="2014-01" />
779824
def month_field_tag(name, value = nil, options = {})
780825
text_field_tag(name, value, options.merge(type: :month))
781826
end
@@ -789,6 +834,20 @@ def month_field_tag(name, value = nil, options = {})
789834
# * <tt>:min</tt> - The minimum acceptable value.
790835
# * <tt>:max</tt> - The maximum acceptable value.
791836
# * <tt>:step</tt> - The acceptable value granularity.
837+
#
838+
# ==== Examples
839+
#
840+
# week_field_tag 'name'
841+
# # => <input id="name" name="name" type="week" />
842+
#
843+
# week_field_tag 'week', '2014-W01'
844+
# # => <input id="week" name="week" type="week" value="2014-W01" />
845+
#
846+
# week_field_tag 'week', nil, class: 'special_input'
847+
# # => <input class="special_input" id="week" name="week" type="week" />
848+
#
849+
# week_field_tag 'week', '2014-W01', class: 'special_input', disabled: true
850+
# # => <input disabled="disabled" class="special_input" id="week" name="week" type="week" value="2014-W01" />
792851
def week_field_tag(name, value = nil, options = {})
793852
text_field_tag(name, value, options.merge(type: :week))
794853
end
@@ -897,6 +956,17 @@ def number_field_tag(name, value = nil, options = {})
897956
# ==== Options
898957
#
899958
# Supports the same options as #number_field_tag.
959+
#
960+
# ==== Examples
961+
#
962+
# range_field_tag 'quantity', '1'
963+
# # => <input id="quantity" name="quantity" type="range" value="1" />
964+
#
965+
# range_field_tag 'quantity', in: 1...10
966+
# # => <input id="quantity" name="quantity" min="1" max="9" type="range" />
967+
#
968+
# range_field_tag 'quantity', min: 1, max: 10, step: 2
969+
# # => <input id="quantity" name="quantity" min="1" max="10" step="2" type="range"
900970
def range_field_tag(name, value = nil, options = {})
901971
number_field_tag(name, value, options.merge(type: :range))
902972
end

0 commit comments

Comments
 (0)