0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Splitting date field into multiple inputs on the form object level (reform)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
>= 0
~> 10.0
~> 3.0

Runtime

~> 1.2.6
~> 1.0.1
 Project Readme

Table of Contents generated with DocToc

  • Purpose
  • Getting Started
  • Usage
  • Available options
    • Generate inputs with a different name base:
    • To omit parts, set the appropriate option below to true:
    • Validate conditionally:
    • These options are delegated to reform's property method:
  • View example
  • Contributing
  • License

Purpose

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.

Getting Started

gem 'multi_part_date'

Or install it yourself as:

$ gem install multi_part_date

Usage

Form object:

class BasicForm < Reform::Form
  multi_part_date :date_of_birth
end

Where date_of_birth is an actual model attribute.

Available options

Generate inputs with a different name base:

as: :birth

Will generate inputs

f.birth_day
f.birth_month
f.birth_year

To omit parts, set the appropriate option below to true:

:discard_day
:discard_month
:discard_year

Validate conditionally:

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.

These options are delegated to reform's property method:

:on
:type

View example

(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

Contributing

Bug reports and pull requests are welcome! 😄 Fork the repo and submit your PR or issue.

License

The gem is available as open source under the terms of the MIT License.