about summary refs log tree commit diff
path: root/config/initializers/simple_form.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-06-10 23:01:56 +0200
committerGitHub <noreply@github.com>2019-06-10 23:01:56 +0200
commitc64eef12069c3476f9956dfaaf6a3a9f91c14e2d (patch)
treec8048db1bc718663c5ed33c8b225544d5e37f98b /config/initializers/simple_form.rb
parentb45f555a0c7a7d50ed7640b938eb8b5a671a0e10 (diff)
parent7778de467cd35fa4a514dd97ced0d19675f3b9d9 (diff)
Merge pull request #1102 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'config/initializers/simple_form.rb')
-rw-r--r--config/initializers/simple_form.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index 386ede654..964526819 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -8,7 +8,16 @@ module AppendComponent
   end
 end
 
+module RecommendedComponent
+  def recommended(wrapper_options = nil)
+    return unless options[:recommended]
+    options[:label_text] = ->(raw_label_text, _required_label_text, _label_present) { safe_join([raw_label_text, ' ', content_tag(:span, I18n.t('simple_form.recommended'), class: 'recommended')]) }
+    nil
+  end
+end
+
 SimpleForm.include_component(AppendComponent)
+SimpleForm.include_component(RecommendedComponent)
 
 SimpleForm.setup do |config|
   # Wrappers are used by the form builder to generate a
@@ -65,6 +74,7 @@ SimpleForm.setup do |config|
     b.use :html5
 
     b.wrapper tag: :div, class: :label_input do |ba|
+      ba.optional :recommended
       ba.use :label
 
       ba.wrapper tag: :div, class: :label_input__wrapper do |bb|