Module: ActiveScaffold::Helpers::FormColumnHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/active_scaffold/bridges/file_column/form_ui.rb,
lib/active_scaffold/bridges/dragonfly/form_ui.rb,
lib/active_scaffold/bridges/paperclip/form_ui.rb,
lib/active_scaffold/bridges/carrierwave/form_ui.rb,
lib/active_scaffold/helpers/form_column_helpers.rb,
lib/active_scaffold/bridges/active_storage/form_ui.rb
Overview
Helpers that assist with the rendering of a Form Column
Instance Method Summary collapse
- #action_for_validation?(record) ⇒ Boolean
- #active_scaffold_add_existing_input(options) ⇒ Object
- #active_scaffold_add_existing_label ⇒ Object
- #active_scaffold_check_all_buttons(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_checkbox_list(column, select_options, associated_ids, options, ui_options: column.options) ⇒ Object
- #active_scaffold_checkbox_option(option, label_method, associated_ids, checkbox_options, li_options = {}) ⇒ Object
- #active_scaffold_enum_options(column, record = nil, ui_options: column.options) ⇒ Object
- #active_scaffold_file_with_content(column, content, options, remove_file_prefix, controls_class) ⇒ Object
- #active_scaffold_file_with_remove_link(column, options, content, remove_file_prefix, controls_class, ui_options: column.options, &block) ⇒ Object
-
#active_scaffold_grouped_options(column, select_options, optgroup) ⇒ Object
Form input methods.
- #active_scaffold_input_active_storage_has_many(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_active_storage_has_one(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_boolean(column, html_options, ui_options: column.options) ⇒ Object
Column.type-based inputs.
- #active_scaffold_input_carrierwave(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_checkbox(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_color(column, options, ui_options: column.options) ⇒ Object
A color picker.
- #active_scaffold_input_date(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_datetime(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_draggable(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_dragonfly(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_email(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid email address (in-browser validation).
- #active_scaffold_input_enum(column, html_options, options = {}, ui_options: column.options) ⇒ Object
- #active_scaffold_input_file_column(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_for(column, scope = nil, options = nil) ⇒ Object
This method decides which input to use for the given column.
- #active_scaffold_input_month(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_number(column, options, ui_options: column.options) ⇒ Object
A spinbox control for number values (in-browser validation).
-
#active_scaffold_input_options(column, scope = nil, options = {}) ⇒ Object
the standard active scaffold options used for class, name and scope.
- #active_scaffold_input_paperclip(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_password(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_plural_association(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_radio(column, html_options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_range(column, options, ui_options: column.options) ⇒ Object
A slider control for number values (in-browser validation).
- #active_scaffold_input_select(column, html_options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_select_multiple(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_singular_association(column, html_options, options = {}, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_telephone(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid phone-number (in-browser validation).
-
#active_scaffold_input_text_options(options = {}) ⇒ Object
the standard active scaffold options used for textual inputs.
- #active_scaffold_input_textarea(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_input_time(column, options, ui_options: column.options) ⇒ Object
-
#active_scaffold_input_url(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid URI (in-browser validation).
- #active_scaffold_input_virtual(column, options) ⇒ Object
- #active_scaffold_input_week(column, options, ui_options: column.options) ⇒ Object
- #active_scaffold_new_record_subform(column, record, html_options, ui_options: column.options, new_record_attributes: nil, locals: {}, skip_link: false) ⇒ Object
-
#active_scaffold_number_input(method, column, options, remove_options = nil, ui_options: column.options) ⇒ Object
A slider control for number values (in-browser validation).
- #active_scaffold_plural_association_options(column, record = nil) ⇒ Object
- #active_scaffold_radio_option(option, selected, column, radio_options, ui_options: column.options) ⇒ Object
- #active_scaffold_refresh_link(column, html_options, record, ui_options = {}) ⇒ Object
- #active_scaffold_render_input(column, options) ⇒ Object
-
#active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #active_scaffold_select_name_with_multiple(options) ⇒ Object
- #active_scaffold_show_new_subform_link(column, record, select_id, subform_id) ⇒ Object
- #active_scaffold_subform_attributes(column, column_css_class = nil, klass = nil, tab_id: nil) ⇒ Object
- #active_scaffold_text_input(method, column, options, remove_options = nil, ui_options: column.options) ⇒ Object
- #active_scaffold_translate_select_options(options) ⇒ Object
- #active_scaffold_translated_option(column, text, value = nil) ⇒ Object
-
#column_numerical_constraints(column, options) ⇒ Object
Try to get numerical constraints from model’s validators.
-
#column_renders_as(column) ⇒ Object
Macro-level rendering decisions for columns.
- #column_scope(column, scope = nil, record = nil) ⇒ Object
- #column_show_add_existing(column, record = nil) ⇒ Object
- #column_show_add_new(column, associated, record) ⇒ Object
- #current_form_columns(record, scope, subform_controller = nil) ⇒ Object
- #field_attributes(column, record) ⇒ Object
- #form_attribute(column, record, scope = nil, only_value = false, col_class = nil) ⇒ Object
- #form_column_is_hidden?(column, record, scope = nil) ⇒ Boolean
- #form_column_label(column, record = nil, scope = nil) ⇒ Object
- #form_hidden_attribute(column, record, scope = nil) ⇒ Object
- #form_hidden_field(column, record, scope) ⇒ Object
-
#in_subform?(column, parent_record, parent_column) ⇒ Boolean
Should this column be displayed in the subform?.
- #label_for(column, options) ⇒ Object
- #numerical_constraints_for_column(column, options) ⇒ Object
- #override_form_field(column) ⇒ Object (also: #override_form_field?)
-
#override_form_field_partial(column) ⇒ Object
the naming convention for overriding form fields with helpers.
-
#override_input(form_ui) ⇒ Object
(also: #override_input?)
the naming convention for overriding form input types with helpers.
-
#override_subform_partial(column, subform_partial) ⇒ Object
add functionality for overriding subform partials from association class path.
-
#partial_for_model(model, partial) ⇒ Object
Form column override signatures.
- #render_column(column, record, renders_as, scope = nil, only_value: false, col_class: nil, **subform_locals) ⇒ Object
- #render_subsection(column, record, scope, form_action, partial: 'form') ⇒ Object
- #subform_label(column, hidden) ⇒ Object
- #subform_partial_for_column(column, klass = nil, ui_options: column.options) ⇒ Object
- #update_columns_options(column, scope, options, force = false, form_columns: nil, url_params: {}) ⇒ Object
Instance Method Details
#action_for_validation?(record) ⇒ Boolean
87 88 89 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 87 def action_for_validation?(record) record&.persisted? ? :update : :create end |
#active_scaffold_add_existing_input(options) ⇒ Object
773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 773 def active_scaffold_add_existing_input() record = .delete(:object) if controller.respond_to?(:record_select_config, true) remote_controller = active_scaffold_controller_for(record_select_config.model).controller_path [:controller] = remote_controller .merge!() record_select_field([:name], nil, ) else = (nested.association, nil, record) ||= active_scaffold_config.model.all = (, :id, :to_label) select_tag 'associated_id', (content_tag(:option, as_(:_select_), value: '') + ) unless .empty? end end |
#active_scaffold_add_existing_label ⇒ Object
788 789 790 791 792 793 794 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 788 def active_scaffold_add_existing_label if controller.respond_to?(:record_select_config, true) record_select_config.model.model_name.human else active_scaffold_config.model.model_name.human end end |
#active_scaffold_check_all_buttons(column, options, ui_options: column.options) ⇒ Object
477 478 479 480 481 482 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 477 def (column, , ui_options: column.) content_tag(:div, class: 'check-buttons') do link_to(as_(:check_all), '#', class: 'check-all') << link_to(as_(:uncheck_all), '#', class: 'uncheck-all') end end |
#active_scaffold_checkbox_list(column, select_options, associated_ids, options, ui_options: column.options) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 484 def active_scaffold_checkbox_list(column, , associated_ids, , ui_options: column.) label_method = [:label_method] || :to_label html = (column, , ui_options: ) html << hidden_field_tag("#{[:name]}[]", '', id: nil) draggable = .delete(:draggable_lists) || [:draggable_lists] html << content_tag(:ul, .merge(class: "#{[:class]} checkbox-list#{' draggable-lists' if draggable}")) do content = [] .each_with_index do |option, i| content << active_scaffold_checkbox_option(option, label_method, associated_ids, name: "#{[:name]}[]", id: "#{[:id]}_#{i}_id") end safe_join content end html end |
#active_scaffold_checkbox_option(option, label_method, associated_ids, checkbox_options, li_options = {}) ⇒ Object
468 469 470 471 472 473 474 475 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 468 def active_scaffold_checkbox_option(option, label_method, associated_ids, , = {}) content_tag(:li, ) do option_id = option.is_a?(Array) ? option[1] : option.id label = option.is_a?(Array) ? option[0] : option.send(label_method) check_box_tag([:name], option_id, associated_ids.include?(option_id), ) << content_tag(:label, label, for: [:id]) end end |
#active_scaffold_enum_options(column, record = nil, ui_options: column.options) ⇒ Object
504 505 506 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 504 def (column, record = nil, ui_options: column.) [:options] end |
#active_scaffold_file_with_content(column, content, options, remove_file_prefix, controls_class) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 403 def active_scaffold_file_with_content(column, content, , remove_file_prefix, controls_class) required = .delete(:required) js_remove_file_code = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show()#{".find('input').attr('required', 'required')" if required}; return false;" js_dont_remove_file_code = "jQuery(this).parents('div.#{controls_class}').find('input.remove_file').val('false'); return false;" object_name, method = [:name].split(/\[(#{column.name})\]/) method.sub!(/#{column.name}/, "#{remove_file_prefix}\\0") fields = block_given? ? yield : '' link_key = [:multiple] ? :remove_files : :remove_file input = file_field(:record, column.name, .merge(onchange: js_dont_remove_file_code)) content_tag(:div, class: controls_class) do content_tag(:div) do safe_join [content, ' | ', fields, hidden_field(object_name, method, value: 'false', class: 'remove_file'), content_tag(:a, as_(link_key), href: '#', onclick: js_remove_file_code)] end << content_tag(:div, input, style: 'display: none') end end |
#active_scaffold_file_with_remove_link(column, options, content, remove_file_prefix, controls_class, ui_options: column.options, &block) ⇒ Object
394 395 396 397 398 399 400 401 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 394 def active_scaffold_file_with_remove_link(column, , content, remove_file_prefix, controls_class, ui_options: column., &block) = (.merge()) if content active_scaffold_file_with_content(column, content, , remove_file_prefix, controls_class, &block) else file_field(:record, column.name, ) end end |
#active_scaffold_grouped_options(column, select_options, optgroup) ⇒ Object
Form input methods
310 311 312 313 314 315 316 317 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 310 def (column, , optgroup) group_column = active_scaffold_config_for(column.association.klass).columns[optgroup] group_label = group_column.[:label_method] if group_column group_label ||= group_column&.association ? :to_label : :to_s .group_by(&optgroup.to_sym).collect do |group, | [group.send(group_label), .collect { |r| [r.send(column.[:label_method] || :to_label), r.id] }] end end |
#active_scaffold_input_active_storage_has_many(column, options, ui_options: column.options) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/active_scaffold/bridges/active_storage/form_ui.rb', line 12 def active_scaffold_input_active_storage_has_many(column, , ui_options: column.) record = [:object] [:multiple] = 'multiple' [:name] += '[]' active_storage = record.send(column.name.to_s) content = active_scaffold_column_active_storage_has_many(record, column, ui_options: ) if active_storage.attached? active_scaffold_file_with_remove_link(column, , content, 'delete_', 'active_storage_controls', ui_options: ) end |
#active_scaffold_input_active_storage_has_one(column, options, ui_options: column.options) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/active_scaffold/bridges/active_storage/form_ui.rb', line 5 def active_scaffold_input_active_storage_has_one(column, , ui_options: column.) record = [:object] active_storage = record.send(column.name.to_s) content = active_scaffold_column_active_storage_has_one(record, column, ui_options: ) if active_storage.attached? active_scaffold_file_with_remove_link(column, , content, 'delete_', 'active_storage_controls', ui_options: ) end |
#active_scaffold_input_boolean(column, html_options, ui_options: column.options) ⇒ Object
Column.type-based inputs
674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 674 def active_scaffold_input_boolean(column, , ui_options: column.) record = .delete(:object) .merge!([:html_options] || {}) = {selected: record.send(column.name), object: record} [:include_blank] = :_select_ if column.null? .merge!() () = [[as_(:true), true], [as_(:false), false]] # rubocop:disable Lint/BooleanSymbol select(:record, column.name, , , ) end |
#active_scaffold_input_carrierwave(column, options, ui_options: column.options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/active_scaffold/bridges/carrierwave/form_ui.rb', line 4 def active_scaffold_input_carrierwave(column, , ui_options: column.) record = [:object] carrierwave = record.send(column.name.to_s) content = get_column_value(record, column) if carrierwave.file.present? active_scaffold_file_with_remove_link(column, , content, 'remove_', 'carrierwave_controls', ui_options: ) do = { name: [:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"), id: "#{[:id]}_cache" } hidden_field(:record, "#{column.name}_cache", ) end end |
#active_scaffold_input_checkbox(column, options, ui_options: column.options) ⇒ Object
598 599 600 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 598 def active_scaffold_input_checkbox(column, , ui_options: column.) check_box(:record, column.name, .merge()) end |
#active_scaffold_input_color(column, options, ui_options: column.options) ⇒ Object
A color picker
656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 656 def active_scaffold_input_color(column, , ui_options: column.) html = [] = () if column.null? no_color = [:object].send(column.name).nil? method = no_color ? :hidden_field : :color_field html << content_tag(:label, check_box_tag('disable', '1', no_color, id: nil, name: nil, class: 'no-color') << " #{as_ [:no_color] || :no_color}") else method = :color_field end html << send(method, :record, column.name, .merge().except(:format, :no_color)) safe_join html end |
#active_scaffold_input_date(column, options, ui_options: column.options) ⇒ Object
687 688 689 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 687 def active_scaffold_input_date(column, , ui_options: column.) active_scaffold_text_input :date_field, column, , ui_options: end |
#active_scaffold_input_datetime(column, options, ui_options: column.options) ⇒ Object
695 696 697 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 695 def active_scaffold_input_datetime(column, , ui_options: column.) active_scaffold_text_input :datetime_local_field, column, , ui_options: end |
#active_scaffold_input_draggable(column, options, ui_options: column.options) ⇒ Object
464 465 466 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 464 def active_scaffold_input_draggable(column, , ui_options: column.) active_scaffold_input_plural_association(column, .merge(draggable_lists: true), ui_options: ) end |
#active_scaffold_input_dragonfly(column, options, ui_options: column.options) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/active_scaffold/bridges/dragonfly/form_ui.rb', line 4 def active_scaffold_input_dragonfly(column, , ui_options: column.) record = [:object] dragonfly = record.send(column.name.to_s) content = active_scaffold_column_dragonfly(record, column, ui_options: ) if dragonfly.present? active_scaffold_file_with_remove_link(column, , content, 'remove_', 'dragonfly_controls', ui_options: ) end |
#active_scaffold_input_email(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid email address (in-browser validation)
618 619 620 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 618 def active_scaffold_input_email(column, , ui_options: column.) active_scaffold_text_input :email_field, column, , ui_options: end |
#active_scaffold_input_enum(column, html_options, options = {}, ui_options: column.options) ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 508 def active_scaffold_input_enum(column, , = {}, ui_options: column.) record = .delete(:object) [:selected] = record.send(column.name) [:object] = record = override_helper_per_model(:active_scaffold_enum_options, record.class) = send(, column, record, ui_options: ).collect do |text, value| active_scaffold_translated_option(column, text, value) end .merge!([:html_options] || {}) .merge!() active_scaffold_select_name_with_multiple () html = select(:record, column.name, , , ) html << active_scaffold_refresh_link(column, , record, ) if [:refresh_link] html end |
#active_scaffold_input_file_column(column, options, ui_options: column.options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_scaffold/bridges/file_column/form_ui.rb', line 5 def active_scaffold_input_file_column(column, , ui_options: column.) record = [:object] if record.send(column.name) # we already have a value? display the form for deletion. remove_file_js = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show(); return false;" = .merge(id: "#{[:id]}_delete", name: [:name].sub("[#{column.name}]", "[delete_#{column.name}]"), value: 'false') custom_hidden_field_tag = hidden_field(:record, column.name, ) content_tag(:div) do content_tag(:div) do safe_join [get_column_value(record, column), custom_hidden_field_tag, '|', content_tag(:a, as_(:remove_file), href: '#', onclick: remove_file_js), content_tag(:div, 'test', style: 'display: none')], ' ' end end else file_column_field('record', column.name, ) end end |
#active_scaffold_input_for(column, scope = nil, options = nil) ⇒ Object
This method decides which input to use for the given column. It does not do any rendering. It only decides which method is responsible for rendering.
7 8 9 10 11 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 7 def active_scaffold_input_for(column, scope = nil, = nil) ||= (column, scope) = (column, scope, ) active_scaffold_render_input(column, ) end |
#active_scaffold_input_month(column, options, ui_options: column.options) ⇒ Object
699 700 701 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 699 def active_scaffold_input_month(column, , ui_options: column.) active_scaffold_text_input :month_field, column, , ui_options: end |
#active_scaffold_input_number(column, options, ui_options: column.options) ⇒ Object
A spinbox control for number values (in-browser validation)
633 634 635 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 633 def active_scaffold_input_number(column, , ui_options: column.) active_scaffold_number_input :number_field, column, , :format, ui_options: end |
#active_scaffold_input_options(column, scope = nil, options = {}) ⇒ Object
the standard active scaffold options used for class, name and scope
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 92 def (column, scope = nil, = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" record = [:object] # Add some HTML5 attributes for in-browser validation and better user experience if column.required?(action_for_validation?(record)) && (!@disable_required_for_new || scope.nil? || record&.persisted?) [:required] = true end [:placeholder] = column.placeholder if column.placeholder.present? # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:parent_id] || params[:id]].compact.join '_'}" id_control += scope_id(scope) if scope classes = "#{column.name}-input" classes += ' numeric-input' if column.number? collapsible_id = "container_#{id_control}" if (column. || column.)[:collapsible] {name: name, class: classes, id: id_control, collapsible_id: collapsible_id}.merge() end |
#active_scaffold_input_paperclip(column, options, ui_options: column.options) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/active_scaffold/bridges/paperclip/form_ui.rb', line 4 def active_scaffold_input_paperclip(column, , ui_options: column.) record = [:object] paperclip = record.send(column.name.to_s) content = active_scaffold_column_paperclip(record, column, ui_options: ) if paperclip.file? active_scaffold_file_with_remove_link(column, , content, 'delete_', 'paperclip_controls', ui_options: ) end |
#active_scaffold_input_password(column, options, ui_options: column.options) ⇒ Object
602 603 604 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 602 def active_scaffold_input_password(column, , ui_options: column.) active_scaffold_text_input :password_field, column, .reverse_merge(autocomplete: 'new-password'), ui_options: end |
#active_scaffold_input_plural_association(column, options, ui_options: column.options) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 445 def active_scaffold_input_plural_association(column, , ui_options: column.) record = .delete(:object) , = (column, record) html = if [:multiple] || .dig(:html_options, :multiple) = .merge([:html_options] || {}) active_scaffold_select_name_with_multiple collection_select(:record, column.name, , :id, [:label_method] || :to_label, .merge(object: record), ) elsif .empty? content_tag(:span, as_(:no_options), class: "#{[:class]} no-options", id: [:id]) << hidden_field_tag("#{[:name]}[]", '', id: nil) else active_scaffold_checkbox_list(column, , .collect(&:id), , ui_options: ) end html << active_scaffold_refresh_link(column, , record, ) if [:refresh_link] html end |
#active_scaffold_input_radio(column, html_options, ui_options: column.options) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 555 def active_scaffold_input_radio(column, , ui_options: column.) record = [:object] .merge!([:html_options] || {}) = if column.association (column.association, nil, record) else = override_helper_per_model(:active_scaffold_enum_options, record.class) send(, column, record, ui_options: ) end selected = record.send(column.association.name) if column.association selected_id = selected&.id if .present? if [:add_new] [:data] ||= {} [:data][:subform_id] = active_scaffold_subform_attributes(column)[:id] = .merge(class: "#{[:class]} hide-new-subform") else = end radios = .map do |option| active_scaffold_radio_option(option, selected_id, column, , ui_options: ) end if [:include_blank] label = [:include_blank] label = as_([:include_blank]) if [:include_blank].is_a?(Symbol) radios.prepend content_tag(:label, (:record, column.name, '', .merge(id: nil)) + label) end if [:add_new] = ([:name], '', selected&.new_record?, .merge(id: nil, class: "#{[:class]} show-new-subform").except(:object)) radios << content_tag(:label, << as_(:create_new)) << active_scaffold_new_record_subform(column, record, , ui_options: , skip_link: true) end safe_join radios else html = content_tag(:span, as_(:no_options), class: "#{[:class]} no-options", id: [:id]) html << hidden_field_tag([:name], '', id: nil) html << active_scaffold_new_record_subform(column, record, , ui_options: ) if [:add_new] html end end |
#active_scaffold_input_range(column, options, ui_options: column.options) ⇒ Object
A slider control for number values (in-browser validation)
638 639 640 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 638 def active_scaffold_input_range(column, , ui_options: column.) active_scaffold_number_input :range_field, column, , :format, ui_options: end |
#active_scaffold_input_select(column, html_options, ui_options: column.options) ⇒ Object
525 526 527 528 529 530 531 532 533 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 525 def active_scaffold_input_select(column, , ui_options: column.) if column.association&.singular? active_scaffold_input_singular_association(column, , ui_options: ) elsif column.association&.collection? active_scaffold_input_plural_association(column, , ui_options: ) else active_scaffold_input_enum(column, , ui_options: ) end end |
#active_scaffold_input_select_multiple(column, options, ui_options: column.options) ⇒ Object
535 536 537 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 535 def active_scaffold_input_select_multiple(column, , ui_options: column.) active_scaffold_input_select(column, .merge(multiple: true), ui_options: ) end |
#active_scaffold_input_singular_association(column, html_options, options = {}, ui_options: column.options) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 331 def active_scaffold_input_singular_association(column, , = {}, ui_options: column.) record = .delete(:object) associated = .include?(:associated) ? .delete(:associated) : record.send(column.association.name) = (column.association, nil, record) .unshift(associated) unless associated.nil? || .include?(associated) method = column.name .merge! selected: associated&.id, include_blank: as_(:_select_), object: record .merge!([:html_options] || {}) .merge!() .delete(:multiple) # no point using multiple in a form for singular assoc, but may be set for field search () html = if (optgroup = .delete(:optgroup)) select(:record, method, (column, , optgroup), , ) else collection_select(:record, method, , :id, [:label_method] || :to_label, , ) end html << active_scaffold_refresh_link(column, , record, ) if [:refresh_link] html << active_scaffold_new_record_subform(column, record, , ui_options: ) if [:add_new] html end |
#active_scaffold_input_telephone(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid phone-number (in-browser validation)
628 629 630 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 628 def active_scaffold_input_telephone(column, , ui_options: column.) active_scaffold_text_input :telephone_field, column, , :format, ui_options: end |
#active_scaffold_input_text_options(options = {}) ⇒ Object
the standard active scaffold options used for textual inputs
81 82 83 84 85 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 81 def ( = {}) [:autocomplete] ||= 'off' [:class] = "#{[:class]} text-input".strip end |
#active_scaffold_input_textarea(column, options, ui_options: column.options) ⇒ Object
606 607 608 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 606 def active_scaffold_input_textarea(column, , ui_options: column.) text_area(:record, column.name, .merge(cols: [:cols], rows: [:rows], size: [:size])) end |
#active_scaffold_input_time(column, options, ui_options: column.options) ⇒ Object
691 692 693 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 691 def active_scaffold_input_time(column, , ui_options: column.) active_scaffold_text_input :time_field, column, , ui_options: end |
#active_scaffold_input_url(column, options, ui_options: column.options) ⇒ Object
A text box, that accepts only valid URI (in-browser validation)
623 624 625 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 623 def active_scaffold_input_url(column, , ui_options: column.) active_scaffold_text_input :url_field, column, , ui_options: end |
#active_scaffold_input_virtual(column, options) ⇒ Object
610 611 612 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 610 def active_scaffold_input_virtual(column, ) active_scaffold_text_input :text_field, column, end |
#active_scaffold_input_week(column, options, ui_options: column.options) ⇒ Object
703 704 705 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 703 def active_scaffold_input_week(column, , ui_options: column.) active_scaffold_text_input :week_field, column, , ui_options: end |
#active_scaffold_new_record_subform(column, record, html_options, ui_options: column.options, new_record_attributes: nil, locals: {}, skip_link: false) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 357 def active_scaffold_new_record_subform(column, record, , ui_options: column., new_record_attributes: nil, locals: {}, skip_link: false) klass = if column.association.polymorphic? && column.association.belongs_to? type = record.send(column.association.foreign_type) column.association.klass(record) if type.present? && ([:add_new] == true || type.in?([:add_new])) else column.association.klass end return content_tag(:div, '') unless klass subform_attrs = active_scaffold_subform_attributes(column, nil, klass) if record.send(column.name)&.new_record? new_record = record.send(column.name) else subform_attrs[:style] = 'display: none' end subform_attrs[:class] << ' optional' scope = [:name].scan(/record(.*)\[#{column.name}\]/).dig(0, 0) new_record ||= klass.new(new_record_attributes) locals = locals.reverse_merge(column: column, parent_record: record, associated: [], show_blank_record: new_record, scope: scope) subform = render(partial: subform_partial_for_column(column, klass, ui_options: ), locals: locals) if [:hide_subgroups] toggable_id = "#{sub_form_id(association: column.name, id: record.id || generated_id(record) || 99_999_999_999)}-div" subform << link_to_visibility_toggle(toggable_id, default_visible: false) end html = content_tag(:div, subform, subform_attrs) return html if skip_link html << active_scaffold_show_new_subform_link(column, record, [:id], subform_attrs[:id]) end |
#active_scaffold_number_input(method, column, options, remove_options = nil, ui_options: column.options) ⇒ Object
A slider control for number values (in-browser validation)
643 644 645 646 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 643 def active_scaffold_number_input(method, column, , = nil, ui_options: column.) = numerical_constraints_for_column(column, ) active_scaffold_text_input method, column, , , ui_options: end |
#active_scaffold_plural_association_options(column, record = nil) ⇒ Object
440 441 442 443 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 440 def (column, record = nil) = record.send(column.association.name) [, | (column.association, nil, record)] end |
#active_scaffold_radio_option(option, selected, column, radio_options, ui_options: column.options) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 539 def active_scaffold_radio_option(option, selected, column, , ui_options: column.) if column.association label_method = [:label_method] || :to_label text = option.send(label_method) value = option.id checked = {checked: selected == value} else text, value = active_scaffold_translated_option(column, *option) end id_key = [:'data-id'] ? :'data-id' : :id = .merge(id_key => "#{[id_key]}-#{value.to_s.parameterize}") .merge!(checked) if checked content_tag(:label, (:record, column.name, value, ) + text) end |
#active_scaffold_refresh_link(column, html_options, record, ui_options = {}) ⇒ Object
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 422 def active_scaffold_refresh_link(column, , record, = {}) = {object: record} if ['data-update_url'] ['data-update_send_form'] = ['data-update_send_form'] ['data-update_send_form_selector'] = ['data-update_send_form_selector'] else scope = [:name].scan(/^record((\[[^\]]*\])*)\[#{column.name}\]/).dig(0, 0) if [:name] = (column, scope.presence, , true) end [:class] = 'refresh-link' if [:refresh_link].is_a?(Hash) text = .dig(:refresh_link, :text) text = as_(text) if text.is_a?(Symbol) .merge! [:refresh_link].except(:text) end link_to(text || as_(:refresh), .delete('data-update_url') || ['data-update_url'], .except(:object)) end |
#active_scaffold_render_input(column, options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 13 def active_scaffold_render_input(column, ) record = [:object] # first, check if the dev has created an override for this specific field if (method = override_form_field(column)) send(method, record, ) # second, check if the dev has specified a valid form_ui for this column elsif column.form_ui && (method = override_input(column.form_ui)) send(method, column, , ui_options: (column. || column.).except(:collapsible)) elsif column.association # if we get here, it's because the column has a form_ui but not one ActiveScaffold knows about. raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" if column.form_ui # its an association and nothing is specified, we will assume form_ui :select active_scaffold_input_select(column, ) elsif column.virtual? [:value] = format_number_value(record.send(column.name), column.) if column.number? active_scaffold_input_virtual(column, ) elsif (method = override_input(column.column_type)) # regular model attribute column # if we (or someone else) have created a custom render option for the column type, use that send(method, column, ) else # final ultimate fallback: use rails' generic input method # for textual fields we pass different options = () if column.text? || column.number? if column.column_type == :string && [:maxlength].blank? [:maxlength] = column.type_for_attribute.limit [:size] ||= [:maxlength].to_i > 30 ? 30 : [:maxlength] end [:value] = format_number_value(record.send(column.name), column.) if column.number? text_field(:record, column.name, .merge(column.).except(:format)) end rescue StandardError => e logger.error "#{e.class.name}: #{e.} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end |
#active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 54 def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil) # rubocop:disable Metrics/ParameterLists if add_class col_class = [] col_class << 'required' if column.required?(action_for_validation?(record)) col_class << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) col_class << 'hidden' if column_renders_as(column) == :hidden col_class << 'checkbox' if column.form_ui == :checkbox col_class = col_class.join(' ') end if (readonly && !record.new_record?) || !record.(crud_type: crud_type, column: column.name) form_attribute(column, record, scope, true, col_class) else renders_as = column_renders_as(column) html = render_column(column, record, renders_as, scope, only_value: false, col_class: col_class) html = content_tag(:div, html, active_scaffold_subform_attributes(column)) if renders_as == :subform html end end |
#active_scaffold_select_name_with_multiple(options) ⇒ Object
325 326 327 328 329 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 325 def active_scaffold_select_name_with_multiple() return if ![:multiple] || [:name].to_s.ends_with?('[]') [:name] = "#{[:name]}[]" end |
#active_scaffold_show_new_subform_link(column, record, select_id, subform_id) ⇒ Object
388 389 390 391 392 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 388 def active_scaffold_show_new_subform_link(column, record, select_id, subform_id) data = {select_id: select_id, subform_id: subform_id, subform_text: as_(:add_existing), select_text: as_(:create_new)} label = data[record.send(column.name)&.new_record? ? :subform_text : :select_text] link_to(label, '#', data: data, class: 'show-new-subform') end |
#active_scaffold_subform_attributes(column, column_css_class = nil, klass = nil, tab_id: nil) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 73 def active_scaffold_subform_attributes(column, column_css_class = nil, klass = nil, tab_id: nil) { class: "sub-form #{active_scaffold_config_for(klass || column.association.klass).subform.layout}-sub-form #{column_css_class} #{column.name}-sub-form", id: sub_form_id(association: column.name, tab_id: tab_id) } end |
#active_scaffold_text_input(method, column, options, remove_options = nil, ui_options: column.options) ⇒ Object
648 649 650 651 652 653 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 648 def active_scaffold_text_input(method, column, , = nil, ui_options: column.) = () = .merge() = .except(*) if .present? send method, :record, column.name, end |
#active_scaffold_translate_select_options(options) ⇒ Object
319 320 321 322 323 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 319 def () [:include_blank] = as_([:include_blank].to_s) if [:include_blank].is_a? Symbol [:prompt] = as_([:prompt].to_s) if [:prompt].is_a? Symbol end |
#active_scaffold_translated_option(column, text, value = nil) ⇒ Object
499 500 501 502 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 499 def active_scaffold_translated_option(column, text, value = nil) value = text if value.nil? [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end |
#column_numerical_constraints(column, options) ⇒ Object
Try to get numerical constraints from model’s validators
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 797 def column_numerical_constraints(column, ) validators = column.active_record_class.validators.select do |v| v.is_a?(ActiveModel::Validations::NumericalityValidator) && v.attributes.include?(column.name) && !v.[:if] && !v.[:unless] end equal_validator = validators.find { |v| v.[:equal_to] } # If there is equal_to constraint - use it (unless otherwise specified by user) if equal_validator && !([:min] || [:max]) equal_to = equal_validator.[:equal_to] return {min: equal_to, max: equal_to} end numerical_constraints = {} # find minimum and maximum from validators # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values only_integer = column.column_type == :integer if column.column only_integer ||= validators.find { |v| v.[:only_integer] }.present? margin = only_integer ? 1 : 0 # Minimum unless [:min] min = validators.filter_map { |v| v.[:greater_than_or_equal_to] }.max greater_than = validators.filter_map { |v| v.[:greater_than] }.max numerical_constraints[:min] = [min, (greater_than + margin if greater_than)].compact.max end # Maximum unless [:max] max = validators.filter_map { |v| v.[:less_than_or_equal_to] }.min less_than = validators.filter_map { |v| v.[:less_than] }.min numerical_constraints[:max] = [max, (less_than - margin if less_than)].compact.min end # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) unless [:step] only_odd_valid = validators.any? { |v| v.[:odd] } only_even_valid = validators.any? { |v| v.[:even] } unless only_odd_valid if !only_integer numerical_constraints[:step] ||= "0.#{'0' * (column.column.scale - 1)}1" if column.column&.scale.to_i.positive? elsif [:min].respond_to?(:even?) && (only_odd_valid || only_even_valid) numerical_constraints[:step] = 2 numerical_constraints[:min] += 1 if only_odd_valid && [:min].even? numerical_constraints[:min] += 1 if only_even_valid && [:min].odd? end numerical_constraints[:step] ||= 'any' unless only_integer end numerical_constraints end |
#column_renders_as(column) ⇒ Object
Macro-level rendering decisions for columns
753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 753 def column_renders_as(column) if column.respond_to? :each :subsection elsif column.active_record_class.locking_column.to_s == column.name.to_s || column.form_ui == :hidden :hidden elsif column.association.nil? || column.form_ui || active_scaffold_config_for(column.association.klass).actions.exclude?(:subform) || override_form_field?(column) :field else :subform end end |
#column_scope(column, scope = nil, record = nil) ⇒ Object
765 766 767 768 769 770 771 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 765 def column_scope(column, scope = nil, record = nil) if column.association&.collection? "#{scope}[#{column.name}][#{record.id || generate_temporary_id(record)}]" else "#{scope}[#{column.name}]" end end |
#column_show_add_existing(column, record = nil) ⇒ Object
294 295 296 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 294 def column_show_add_existing(column, record = nil) column.allow_add_existing && (column.association, record).positive? end |
#column_show_add_new(column, associated, record) ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 298 def column_show_add_new(column, associated, record) assoc = column.association value = assoc.singular? value ||= assoc.collection? && !assoc.readonly? && (!assoc.through? || !assoc.through_reflection.collection?) value &&= false unless assoc.klass.(crud_type: :create) value end |
#current_form_columns(record, scope, subform_controller = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 114 def current_form_columns(record, scope, subform_controller = nil) if scope subform_controller.active_scaffold_config.subform.columns.visible_columns_names elsif %i[new create edit update render_field].include? action_name.to_sym # disable update_columns for inplace_edit (GET render_field) return if action_name == 'render_field' && request.get? active_scaffold_config.send(record.new_record? ? :create : :update).columns.visible_columns_names end end |
#field_attributes(column, record) ⇒ Object
153 154 155 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 153 def field_attributes(column, record) {} end |
#form_attribute(column, record, scope = nil, only_value = false, col_class = nil) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 205 def form_attribute(column, record, scope = nil, only_value = false, col_class = nil) = (column, scope, object: record) collapsible_id = .delete :collapsible_id attributes = field_attributes(column, record) attributes[:class] = "#{attributes[:class]} #{col_class}" if col_class.present? if only_value field = content_tag(:span, get_column_value(record, column), .except(:name, :object)) if column.association.nil? || column.association.belongs_to? # hidden field probably not needed, but leaving it just in case # but it isn't working for assocations which are not belongs_to method = column.association ? column.association.foreign_key : column.name field << hidden_field(:record, method, ) end else field = active_scaffold_input_for column, scope, end if field field << loading_indicator_tag(action: :render_field, id: params[:id]) if column.update_columns desc = column.description(record, scope) field << content_tag(:span, desc, class: 'description') if desc.present? end label = label_tag(label_for(column, ), form_column_label(column, record, scope)) label << h(' ') << link_to_visibility_toggle(collapsible_id) if collapsible_id content_tag :dl, attributes do content_tag(:dt, label) << content_tag(:dd, field, id: collapsible_id) end end |
#form_column_is_hidden?(column, record, scope = nil) ⇒ Boolean
195 196 197 198 199 200 201 202 203 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 195 def form_column_is_hidden?(column, record, scope = nil) if column.hide_form_column_if.respond_to?(:call) column.hide_form_column_if.call(record, column, scope) elsif column.hide_form_column_if.is_a?(Symbol) record.send(column.hide_form_column_if) else column.hide_form_column_if end end |
#form_column_label(column, record = nil, scope = nil) ⇒ Object
238 239 240 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 238 def form_column_label(column, record = nil, scope = nil) column.label(record, scope) end |
#form_hidden_attribute(column, record, scope = nil) ⇒ Object
246 247 248 249 250 251 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 246 def form_hidden_attribute(column, record, scope = nil) content_tag :dl, style: 'display: none' do content_tag(:dt, '') << content_tag(:dd, form_hidden_field(column, record, scope)) end end |
#form_hidden_field(column, record, scope) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 253 def form_hidden_field(column, record, scope) = (column, scope) if column.association&.collection? associated = record.send(column.name) if associated.blank? hidden_field_tag [:name], '', else [:name] += '[]' fields = associated.map do |r| hidden_field_tag [:name], r.id, .merge(id: [:id] + "_#{r.id}") end safe_join fields, '' end elsif column.association hidden_field_tag [:name], record.send(column.name)&.id, else hidden_field :record, column.name, .merge(object: record) end end |
#in_subform?(column, parent_record, parent_column) ⇒ Boolean
Should this column be displayed in the subform?
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 274 def in_subform?(column, parent_record, parent_column) return true unless column.association if column.association.reverse.nil? # Polymorphic associations can't appear because they *might* be the reverse association return false if column.association.polymorphic? # A column shouldn't be in the subform if it's the reverse association to the parent !column.association.inverse_for?(parent_record.class) elsif column.association.reverse == parent_column.name if column.association.polymorphic? column.association.name != parent_column.association.as else !column.association.inverse_for?(parent_record.class) end else true end end |
#label_for(column, options) ⇒ Object
234 235 236 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 234 def label_for(column, ) [:id] unless column.form_ui == :select && column.association&.collection? end |
#numerical_constraints_for_column(column, options) ⇒ Object
850 851 852 853 854 855 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 850 def numerical_constraints_for_column(column, ) constraints = Rails.cache.fetch("#{column.cache_key}#numerical_constraints") do column_numerical_constraints(column, ) end constraints.merge() end |
#override_form_field(column) ⇒ Object Also known as: override_form_field?
732 733 734 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 732 def override_form_field(column) override_helper column, 'form_column' end |
#override_form_field_partial(column) ⇒ Object
the naming convention for overriding form fields with helpers
728 729 730 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 728 def override_form_field_partial(column) partial_for_model(column.active_record_class, "#{clean_column_name(column.name)}_form_column") end |
#override_input(form_ui) ⇒ Object Also known as: override_input?
the naming convention for overriding form input types with helpers
738 739 740 741 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 738 def override_input(form_ui) method = "active_scaffold_input_#{form_ui}" method if respond_to? method end |
#override_subform_partial(column, subform_partial) ⇒ Object
add functionality for overriding subform partials from association class path
723 724 725 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 723 def override_subform_partial(column, subform_partial) partial_for_model(column.association.klass, subform_partial) if column_renders_as(column) == :subform end |
#partial_for_model(model, partial) ⇒ Object
Form column override signatures
711 712 713 714 715 716 717 718 719 720 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 711 def partial_for_model(model, partial) controller = active_scaffold_controller_for(model) while controller.uses_active_scaffold? path = File.join(controller.controller_path, partial) return path if template_exists?(path, true) controller = controller.superclass end nil end |
#render_column(column, record, renders_as, scope = nil, only_value: false, col_class: nil, **subform_locals) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 176 def render_column(column, record, renders_as, scope = nil, only_value: false, col_class: nil, **subform_locals) if form_column_is_hidden?(column, record, scope) # creates an element that can be replaced by the update_columns routine, # but will not affect the value of the submitted form in this state: # <dl><input type="hidden" class="<%= column.name %>-input"></dl> content_tag :dl, style: 'display: none' do hidden_field_tag(nil, nil, class: "#{column.name}-input") end elsif (partial = override_form_field_partial(column)) render partial, column: column, only_value: only_value, scope: scope, col_class: col_class, record: record elsif renders_as == :field || override_form_field?(column) form_attribute(column, record, scope, only_value, col_class) elsif renders_as == :subform render 'form_association', subform_locals.slice(:tabbed_by, :tab_value, :tab_id).merge(column: column, scope: scope, parent_record: record) else form_hidden_attribute(column, record, scope) end end |
#render_subsection(column, record, scope, form_action, partial: 'form') ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 157 def render_subsection(column, record, scope, form_action, partial: 'form') subsection_id = sub_section_id(sub_section: column.label) locals = {columns: column, form_action: form_action, scope: scope} header = content_tag(:h5) do h(column.label) << link_to_visibility_toggle(subsection_id, default_visible: !column.collapsed) end if column.tabbed_by locals[:tabbed_by] = column.tabbed_by header << content_tag(:div, id: subsection_id) do active_scaffold_tabbed_by(column, record, scope, subsection_id) do |tab_value, tab_id| render partial, locals.merge(subsection_id: "#{subsection_id}-#{tab_id}", tab_id: tab_id, tab_value: tab_value) end end else header << render(partial, locals.merge(subsection_id: subsection_id)) end end |
#subform_label(column, hidden) ⇒ Object
242 243 244 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 242 def subform_label(column, hidden) column.label unless hidden end |
#subform_partial_for_column(column, klass = nil, ui_options: column.options) ⇒ Object
744 745 746 747 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 744 def subform_partial_for_column(column, klass = nil, ui_options: column.) subform_partial = "#{[:layout] || active_scaffold_config_for(klass || column.association.klass).subform.layout}_subform" override_subform_partial(column, subform_partial) || subform_partial end |
#update_columns_options(column, scope, options, force = false, form_columns: nil, url_params: {}) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/active_scaffold/helpers/form_column_helpers.rb', line 125 def (column, scope, , force = false, form_columns: nil, url_params: {}) record = [:object] subform_controller = controller.class.active_scaffold_controller_for(record.class) if scope if @main_columns && (scope.nil? || subform_controller == controller.class) form_columns ||= @main_columns.visible_columns_names end form_columns ||= current_form_columns(record, scope, subform_controller) if force || (form_columns && column.update_columns && (column.update_columns & form_columns).present?) url_params.reverse_merge! params_for(action: 'render_field', column: column.name, id: record.to_param) if nested? && scope url_params[:nested] = url_params.slice(:parent_scaffold, :association, nested.param_name) url_params = url_params.except(:parent_scaffold, :association, nested.param_name) end if scope url_params[:parent_controller] ||= url_params[:controller].gsub(%r{^/}, '') url_params[:controller] = subform_controller.controller_path url_params[:scope] = scope url_params[:parent_id] = params[:parent_id] || params[:id] end [:class] = "#{[:class]} update_form".strip ['data-update_url'] = url_for(url_params) ['data-update_send_form'] = column.send_form_on_update_column ['data-update_send_form_selector'] = column.[:send_form_selector] if column.[:send_form_selector] end end |