Skip to content

Commit

Permalink
Add weekday input.
Browse files Browse the repository at this point in the history
Closes #1770
  • Loading branch information
nashby committed Jul 12, 2024
1 parent 246c797 commit 14b6b2e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/simple_form/inputs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ module Inputs
autoload :RichTextAreaInput
autoload :StringInput
autoload :TextInput
autoload :WeekdayInput
end
end
14 changes: 14 additions & 0 deletions lib/simple_form/inputs/weekday_input.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions test/inputs/weekday_input_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
# encoding: UTF-8
require 'test_helper'

class WeekdayInputTest < ActionView::TestCase
test 'input generates a weekday select' do
if ActionView::VERSION::MAJOR >= 7
with_input_for @user, :born_at, :weekday
assert_select 'select.weekday#user_born_at'
end
end

test 'input generates a weekday select that accepts placeholder' do
if ActionView::VERSION::MAJOR >= 7
with_input_for @user, :born_at, :weekday, placeholder: 'Put in a weekday'
assert_select 'select.weekday[placeholder="Put in a weekday"]'
end
end
end

0 comments on commit 14b6b2e

Please sign in to comment.