From 916a29d84ce7ec3848c90a64a74f88ea44ed8f12 Mon Sep 17 00:00:00 2001 From: gazayas Date: Tue, 8 Aug 2023 18:16:57 +0900 Subject: [PATCH 1/2] Fix html option settings for objects that have multiple values --- .../lib/scaffolding/transformer.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb b/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb index 140741e7d..b64676e2e 100644 --- a/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb +++ b/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb @@ -841,14 +841,22 @@ def valid_#{collection_name} field_options[:color_picker_options] = "t('#{child.pluralize.underscore}.fields.#{name}.options')" end + # When rendering a super_select element we simply use `multiple: true` as an option, + # but all other fields require `html_options {multiple: true}` to work. + if is_multiple + if type == "super_select" + field_options[:multiple] = "true" + else + field_attributes[:multiple] = "true" + end + end + valid_values = if is_id "valid_#{name_without_id.pluralize}" elsif is_ids "valid_#{collection_name}" end - field_options[:multiple] = "true" if is_multiple - # https://stackoverflow.com/questions/21582464/is-there-a-ruby-hashto-s-equivalent-for-the-new-hash-syntax if field_options.any? || options.any? field_options_key = if ["buttons", "super_select", "options"].include?(type) From 67f9ce5aabc994cc921a770abed72efa6cf4c49b Mon Sep 17 00:00:00 2001 From: gazayas Date: Tue, 8 Aug 2023 18:27:22 +0900 Subject: [PATCH 2/2] Write comment about super select multiple value correctly --- bullet_train-super_scaffolding/lib/scaffolding/transformer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb b/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb index b64676e2e..647886d50 100644 --- a/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb +++ b/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb @@ -841,8 +841,8 @@ def valid_#{collection_name} field_options[:color_picker_options] = "t('#{child.pluralize.underscore}.fields.#{name}.options')" end - # When rendering a super_select element we simply use `multiple: true` as an option, - # but all other fields require `html_options {multiple: true}` to work. + # When rendering a super_select element we need to use `html_options: {multiple: true}`, + # but all other fields simply use `multiple: true` to work. if is_multiple if type == "super_select" field_options[:multiple] = "true"