@@ -123,6 +123,52 @@ def file_field(method, options = {})
123123 end
124124 end
125125
126+ # Wrapper around radio button. Example usage:
127+ #
128+ # radio_button :choice, "value", bootstrap: {label: {text: "Do you agree?"}}
129+ #
130+ def radio_button ( method , tag_value , options = { } )
131+ bootstrap = form_bootstrap . scoped ( options . delete ( :bootstrap ) )
132+ return super if bootstrap . disabled
133+
134+ help_text = draw_help ( bootstrap )
135+ errors = draw_errors ( bootstrap , method )
136+
137+ add_css_class! ( options , "form-check-input" )
138+ add_css_class! ( options , "is-invalid" ) if errors . present?
139+
140+ label_text = nil
141+ if ( custom_text = bootstrap . label [ :text ] ) . present?
142+ label_text = custom_text
143+ end
144+
145+ fieldset_css_class = "form-group"
146+ fieldset_css_class += " row" if bootstrap . horizontal?
147+ fieldset_css_class += " #{ bootstrap . inline_margin_class } " if bootstrap . inline?
148+
149+ content_tag ( :fieldset , class : fieldset_css_class ) do
150+ draw_control_column ( bootstrap , offset : true ) do
151+ if bootstrap . custom_control
152+ content_tag ( :div , class : "custom-control custom-radio" ) do
153+ add_css_class! ( options , "custom-control-input" )
154+ remove_css_class! ( options , "form-check-input" )
155+ concat super ( method , tag_value , options )
156+ concat label ( method , label_text , value : tag_value , class : "custom-control-label" )
157+ concat errors if errors . present?
158+ concat help_text if help_text . present?
159+ end
160+ else
161+ content_tag ( :div , class : "form-check" ) do
162+ concat super ( method , tag_value , options )
163+ concat label ( method , label_text , value : tag_value , class : "form-check-label" )
164+ concat errors if errors . present?
165+ concat help_text if help_text . present?
166+ end
167+ end
168+ end
169+ end
170+ end
171+
126172 # Wrapper around checkbox. Example usage:
127173 #
128174 # checkbox :agree, bootstrap: {label: {text: "Do you agree?"}}
@@ -186,7 +232,7 @@ def collection_radio_buttons(method, collection, value_method, text_method, opti
186232
187233 args = [ bootstrap , :radio_button , method , collection , value_method , text_method , options , html_options ]
188234 draw_choices ( *args ) do |m , v , opts |
189- radio_button ( m , v , opts )
235+ radio_button ( m , v , opts . merge ( bootstrap : { disabled : true } ) )
190236 end
191237 end
192238
@@ -208,7 +254,7 @@ def collection_check_boxes(method, collection, value_method, text_method, option
208254 content << draw_choices ( *args ) do |m , v , opts |
209255 opts [ :multiple ] = true
210256 opts [ :include_hidden ] = false
211- ActionView :: Helpers :: FormBuilder . instance_method ( : check_box) . bind ( self ) . call ( m , opts , v )
257+ check_box ( m , opts . merge ( bootstrap : { disabled : true } ) , v )
212258 end
213259 end
214260
0 commit comments