Table of Contents generated with DocToc
Easy implementation of multiple date part fields on the form object level.
Conceptually it works very similar to Rails date_select helper, e.g. breaks up date month, day and year into separate inputs on the front-end, while parsing to one model attribute on the back-end.
The difference is 1) It allows you to style date part inputs however you want and 2) This is an extension to reform gem and works on form object level.
gem 'multi_part_date'
Or install it yourself as:
$ gem install multi_part_date
Form object:
class BasicForm < Reform::Form
multi_part_date :date_of_birth
end
Where date_of_birth
is an actual model attribute.
as: :birth
Will generate inputs
f.birth_day
f.birth_month
f.birth_year
:discard_day
:discard_month
:discard_year
validate_if: :some_method
The above method needs to be defined in the form object.
Note that date is validated by default.
This gem uses Date.valid_date?
to determine if the date is valid.
:on
:type
(using simple_form here & written in slim)
simple_form_for @basic_form do |f|
= f.input :birth_month
= f.input :birth_day
= f.input :birth_year
Bug reports and pull requests are welcome! 😄 Fork the repo and submit your PR or issue.
The gem is available as open source under the terms of the MIT License.