File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,10 @@ def errors_on(name, options={})
3434 hide_attribute_name = options [ :hide_attribute_name ] || false
3535 custom_class = options [ :custom_class ] || false
3636
37- tag . div ( class : custom_class || "invalid-feedback" , id : field_id ( name , :feedback ) ) do
37+ tag . div (
38+ class : custom_class || "invalid-feedback" ,
39+ id : options [ :id ] . present? ? "#{ options [ :id ] } _feedback" : field_id ( name , :feedback )
40+ ) do
3841 errors = if hide_attribute_name
3942 object . errors [ name ]
4043 else
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ def bootstrap_field(field_name)
2424
2525 def bootstrap_select_group ( field_name )
2626 define_method ( :"#{ field_name } _with_bootstrap" ) do |name , options = { } , html_options = { } |
27+ # Specifying the id for a select doesn't work. The Rails helpers need to generate
28+ # what they generate, and that includes the ids for each select option.
2729 options . delete ( :id )
2830 html_options = html_options . reverse_merge ( control_class : "form-select" )
2931 form_group_builder ( name , options , html_options ) do
Original file line number Diff line number Diff line change @@ -1596,6 +1596,19 @@ def warn(message, ...)
15961596 assert_equivalent_html expected , @builder . errors_on ( :email , custom_class : "custom-error-class" )
15971597 end
15981598
1599+ test "errors_on with specified id:" do
1600+ @user . email = nil
1601+ assert @user . invalid?
1602+
1603+ expected = <<~HTML
1604+ < div class ="invalid-feedback " id ="custom-id_feedback ">
1605+ Email can't be blank, Email is too short (minimum is 5 characters)
1606+ </ div >
1607+ HTML
1608+
1609+ assert_equivalent_html expected , @builder . errors_on ( :email , id : "custom-id" )
1610+ end
1611+
15991612 test "horizontal-style forms" do
16001613 expected = <<~HTML
16011614 < form accept-charset ="UTF-8 " action ="/users " class ="new_user " id ="new_user " method ="post ">
You can’t perform that action at this time.
0 commit comments