diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7d57da..ec90eaba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased * Remove redundant `aria-required` attribute for required fields. [@aduth](https://github.com/aduth) +* Add `weekday` input. [@nashby](https://github.com/nashby) ## 5.3.1 diff --git a/README.md b/README.md index 1f516d9f..97dc60d0 100644 --- a/README.md +++ b/README.md @@ -621,6 +621,7 @@ Mapping | Generated HTML Element | Database Column Type `datetime` | `datetime select` | `datetime/timestamp` `date` | `date select` | `date` `time` | `time select` | `time` +`weekday` | `select` (weekdays as options) | - `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations diff --git a/lib/simple_form/inputs.rb b/lib/simple_form/inputs.rb index 2485d391..2476debf 100644 --- a/lib/simple_form/inputs.rb +++ b/lib/simple_form/inputs.rb @@ -22,5 +22,6 @@ module Inputs autoload :RichTextAreaInput autoload :StringInput autoload :TextInput + autoload :WeekdayInput end end diff --git a/lib/simple_form/inputs/weekday_input.rb b/lib/simple_form/inputs/weekday_input.rb new file mode 100644 index 00000000..131ae2cc --- /dev/null +++ b/lib/simple_form/inputs/weekday_input.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +module SimpleForm + module Inputs + class WeekdayInput < CollectionSelectInput + enable :placeholder + + def input(wrapper_options = nil) + merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) + + @builder.weekday_select(attribute_name, input_options, merged_input_options) + end + end + end +end diff --git a/test/inputs/weekday_input_test.rb b/test/inputs/weekday_input_test.rb new file mode 100644 index 00000000..4319a5e7 --- /dev/null +++ b/test/inputs/weekday_input_test.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +# encoding: UTF-8 +require 'test_helper' + +class WeekdayInputTest < ActionView::TestCase + test 'input generates a weekday select' do + with_input_for @user, :born_at, :weekday + assert_select 'select.weekday#user_born_at' + end + + test 'input generates a weekday select that accepts placeholder' do + with_input_for @user, :born_at, :weekday, placeholder: 'Put in a weekday' + assert_select 'select.weekday[placeholder="Put in a weekday"]' + end +end