Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@ def create_widget(form, attrib, format: nil, hide_excludable: true, hide_fixed:
widget = attrib.widget
field_options = attrib.field_options(fmt: format)
all_options = attrib.all_options(fmt: format)
wrapper_present = field_options[:wrapper].is_a?(Hash) && field_options[:wrapper].present?
wrap_params = (wrapper_present ? field_options[:wrapper] : {})

if attrib.fixed?
return render :partial => "batch_connect/session_contexts/fixed", :locals => { form: form, attrib: attrib, field_options: field_options, format: format }
end

rendered = case widget
when 'select'
form.select(attrib.id, attrib.select_choices(hide_excludable: hide_excludable), field_options, attrib.html_options)
form.select(attrib.id, attrib.select_choices(hide_excludable: hide_excludable), field_options, attrib.all_options)
when 'resolution_field'
resolution_field(form, attrib.id, all_options)
when 'check_box'
form.form_group attrib.id, help: field_options[:help] do
form.form_group(attrib.id, help: field_options[:help], **wrap_params) do
form.check_box attrib.id, all_options, attrib.checked_value, attrib.unchecked_value
end
when 'radio', 'radio_button'
form.form_group attrib.id, help: field_options[:help] do
form.form_group(attrib.id, help: field_options[:help], **wrap_params) do
opts = {
label: label_tag(attrib.id, attrib.label),
checked: (attrib.value.presence || attrib.field_options[:checked])
}
content_tag(:div, id: [form.object_name, attrib.id].join('_')) do
content_tag(:div, id: [form.object_name, attrib.id].join('_'), **field_options) do
form.collection_radio_buttons(attrib.id, attrib.select_choices, :second, :first, **opts)
end
end
when 'path_selector'
form.form_group(attrib.id) do
render(partial: 'path_selector', locals: { form: form, attrib: attrib, field_options: field_options })
form.form_group(attrib.id, field_options[:wrapper]) do
render(partial: 'path_selector', locals: { form: form, attrib: attrib, field_options: field_options.except(:wrapper) })
end
when 'file_attachments'
render :partial => "batch_connect/session_contexts/file_attachments", :locals => { form: form, attrib: attrib, field_options: field_options }
Expand All @@ -50,11 +52,12 @@ def create_widget(form, attrib, format: nil, hide_excludable: true, hide_fixed:
end

def resolution_field(form, id, opts = {})
content_tag(:div, id: "#{id}_group", class: "mb3") do
wrapper_present = opts[:wrapper].is_a?(Hash) && opts[:wrapper].present?
content_tag(:div, id: "#{id}_group", class: "mb-3", **(wrapper_present ? opts[:wrapper] : {})) do
concat form.label(id, opts[:label])
concat form.hidden_field(id, id: "#{id}_field")
concat(
content_tag(:div, class: "row mb-3") do
content_tag(:div, id:[form.object_name, id].join('_'), class: "row mb-3", **opts) do
concat (
content_tag(:div, class: "col-sm-6") do
concat (
Expand Down
7 changes: 4 additions & 3 deletions apps/dashboard/app/javascript/dynamic_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,17 @@ function updateVisibility(event, changeId) {
});

if (changeElement === undefined || changeElement.length <= 0) return;


const defaultHidden = $(`#${changeId}`).attr('hide_by_default') || false
const elementInfo = getWidgetInfo(changeId);
// safe to access directly?
const hide = hideLookup[id].get(changeId, val);
if ((hide === false) || (hide === undefined && !initializing)) {
if((hide === false) || (hide === undefined && !initializing && !defaultHidden)) {
changeElement.show();
// Pass text into the aria stream
const addMsg = `Revealed form item ${elementInfo}`;
ariaStream(addMsg)
} else if (hide === true) {
} else if ((hide === true) || (hide === undefined && !initializing && defaultHidden)) {
changeElement.hide();
const rmMsg = `Hid form item ${elementInfo}`;
ariaStream(rmMsg);
Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/app/lib/smart_attributes/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def help_html(fmt: nil)
OodAppkit.markdown.render(help(fmt: fmt)).html_safe
end

def default_hide_wrapper
!opts[:hide_by_default] ? '' : {style: 'display: none'}
end
# Whether this attribute is required
# @return [Boolean] is required
def required
Expand Down Expand Up @@ -148,7 +151,8 @@ def field_options(fmt: nil)
end.merge({
label: label(fmt: fmt),
help: help_html(fmt: fmt),
required: required
required: required,
wrapper: default_hide_wrapper
})
end

Expand Down
Loading
Loading