@@ -511,7 +511,7 @@ def active_scaffold_file_with_remove_link(content, options, controls_class, link
511511 end
512512
513513 def active_scaffold_refresh_link ( column , html_options , record , ui_options = { } )
514- link_options = { object : record }
514+ link_options = { object : record , data : { field_selector : ui_options [ :field_selector ] || "# #{ html_options [ :id ] } " } }
515515 if html_options [ 'data-update_url' ]
516516 link_options [ 'data-update_send_form' ] = html_options [ 'data-update_send_form' ]
517517 link_options [ 'data-update_send_form_selector' ] = html_options [ 'data-update_send_form_selector' ]
@@ -651,6 +651,54 @@ def active_scaffold_radio_option(option, selected, column, radio_options, ui_opt
651651 content_tag ( :label , radio_button ( :record , column . name , value , radio_options ) + text )
652652 end
653653
654+ def active_scaffold_input_radio_content ( column , record , options , html_options , ui_options )
655+ if ui_options [ :add_new ]
656+ add_new_subform = ui_options [ :add_new ] == true || ui_options [ :add_new ] [ :mode ] . in? ( [ nil , :subform ] )
657+ if add_new_subform
658+ html_options [ :data ] ||= { }
659+ html_options [ :data ] [ :subform_id ] = active_scaffold_subform_attributes ( column , ui_options : ui_options ) [ :id ]
660+ end
661+ radio_html_options = html_options . merge ( class : "#{ html_options [ :class ] } hide-new-subform" )
662+ else
663+ radio_html_options = html_options
664+ end
665+
666+ selected = record . send ( column . association . name ) if column . association
667+ radios = options . map do |option |
668+ active_scaffold_radio_option ( option , selected &.id , column , radio_html_options , ui_options : ui_options )
669+ end
670+
671+ if ui_options [ :include_blank ]
672+ label = ui_options [ :include_blank ]
673+ label = as_ ( ui_options [ :include_blank ] ) if ui_options [ :include_blank ] . is_a? ( Symbol )
674+ radio_id = "#{ html_options [ :id ] } -"
675+ radios . prepend content_tag ( :label , radio_button ( :record , column . name , '' , html_options . merge ( id : radio_id ) ) + label )
676+ end
677+ if ui_options [ :add_new ]
678+ if add_new_subform
679+ create_new = content_tag ( :label ) do
680+ radio_button_tag ( html_options [ :name ] , '' , selected &.new_record? , html_options . merge (
681+ id : "#{ html_options [ :id ] } -create_new" , class : "#{ html_options [ :class ] } show-new-subform"
682+ ) . except ( :object ) ) <<
683+ active_scaffold_add_new_text ( ui_options [ :add_new ] , :add_new_text , :create_new )
684+ end
685+ radios << create_new
686+ skip_link = true
687+ else
688+ ui_options = ui_options . merge ( add_new : ui_options [ :add_new ] . merge (
689+ url_options : {
690+ parent_scope : html_options [ :name ] . gsub ( /^record|\[ [^\] ]*\] $/ , '' ) . presence ,
691+ radio_data : html_options . slice ( *html_options . keys . grep ( /^data-update_/ ) )
692+ }
693+ ) )
694+ radios << content_tag ( :span , '' , class : 'new-radio-container' , id : html_options [ :id ] )
695+ end
696+ radios << active_scaffold_add_new ( column , record , html_options , ui_options : ui_options , skip_link : skip_link )
697+ end
698+
699+ safe_join radios
700+ end
701+
654702 def active_scaffold_input_radio ( column , html_options , ui_options : column . options )
655703 record = html_options [ :object ]
656704 html_options . merge! ( ui_options [ :html_options ] || { } )
@@ -663,59 +711,19 @@ def active_scaffold_input_radio(column, html_options, ui_options: column.options
663711 send ( enum_options_method , column , record , ui_options : ui_options )
664712 end
665713
666- selected = record . send ( column . association . name ) if column . association
667- selected_id = selected &.id
668714 if options . present?
669- if ui_options [ :add_new ]
670- add_new_subform = ui_options [ :add_new ] == true || ui_options [ :add_new ] [ :mode ] . in? ( [ nil , :subform ] )
671- if add_new_subform
672- html_options [ :data ] ||= { }
673- html_options [ :data ] [ :subform_id ] = active_scaffold_subform_attributes ( column , ui_options : ui_options ) [ :id ]
674- end
675- radio_html_options = html_options . merge ( class : "#{ html_options [ :class ] } hide-new-subform" )
676- else
677- radio_html_options = html_options
678- end
679- radios = options . map do |option |
680- active_scaffold_radio_option ( option , selected_id , column , radio_html_options , ui_options : ui_options )
681- end
682- if ui_options [ :include_blank ]
683- label = ui_options [ :include_blank ]
684- label = as_ ( ui_options [ :include_blank ] ) if ui_options [ :include_blank ] . is_a? ( Symbol )
685- radio_id = "#{ html_options [ :id ] } -"
686- radios . prepend content_tag ( :label , radio_button ( :record , column . name , '' , html_options . merge ( id : radio_id ) ) + label )
687- end
688- if ui_options [ :add_new ]
689- if add_new_subform
690- create_new = content_tag ( :label ) do
691- radio_button_tag ( html_options [ :name ] , '' , selected &.new_record? , html_options . merge (
692- id : "#{ html_options [ :id ] } -create_new" , class : "#{ html_options [ :class ] } show-new-subform"
693- ) . except ( :object ) ) <<
694- active_scaffold_add_new_text ( ui_options [ :add_new ] , :add_new_text , :create_new )
695- end
696- radios << create_new
697- skip_link = true
698- else
699- ui_options = ui_options . merge ( add_new : ui_options [ :add_new ] . merge (
700- url_options : {
701- parent_scope : html_options [ :name ] . gsub ( /^record|\[ [^\] ]*\] $/ , '' ) . presence ,
702- radio_data : html_options . slice ( *html_options . keys . grep ( /^data-update_/ ) )
703- }
704- ) )
705- radios << content_tag ( :span , '' , class : 'new-radio-container' , id : html_options [ :id ] )
706- end
707- radios << active_scaffold_add_new ( column , record , html_options , ui_options : ui_options , skip_link : skip_link )
708- end
709- safe_join radios
715+ html = active_scaffold_input_radio_content ( column , record , options , html_options , ui_options )
710716 else
711- html = content_tag ( :span , as_ ( :no_options ) , class : "#{ html_options [ :class ] } no-options" , id : html_options [ :id ] )
712- html << hidden_field_tag ( html_options [ :name ] , '' , id : nil )
717+ html = content_tag ( :span , as_ ( :no_options ) , class : "#{ html_options [ :class ] } no-options" )
718+ html << hidden_field_tag ( html_options [ :name ] , '' , id : html_options [ :id ] )
713719 if ui_options [ :add_new ]
714720 html = content_tag ( :div , html , class : 'select-field' ) <<
715721 active_scaffold_add_new ( column , record , html_options , ui_options : ui_options )
716722 end
717723 html
718724 end
725+ html << active_scaffold_refresh_link ( column , html_options , record , ui_options . merge ( field_selector : "[name=\" #{ html_options [ :name ] } \" ]" ) ) if ui_options [ :refresh_link ]
726+ html
719727 end
720728
721729 def active_scaffold_input_checkbox ( column , options , ui_options : column . options )
0 commit comments