From e823fc93c6d5b297de6e8ef0c581a581b246d73a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 11 Jan 2024 17:32:46 +0100 Subject: [PATCH] Add richtext input type for form builder This makes it easier to add a tinymce editor to a form field. Nice for migrating a resource form from using the `"tinymce"` class. --- lib/alchemy/forms/builder.rb | 7 ++++ spec/libraries/forms/builder_spec.rb | 48 ++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/alchemy/forms/builder.rb b/lib/alchemy/forms/builder.rb index e0c6f95f5e..a82548fa7b 100644 --- a/lib/alchemy/forms/builder.rb +++ b/lib/alchemy/forms/builder.rb @@ -43,6 +43,13 @@ def datepicker(attribute_name, options = {}) template.content_tag("alchemy-datepicker", date_field, type: type) end + # Renders a simple_form input that displays a richtext editor + # + def richtext(attribute_name, options = {}) + text_area = input(attribute_name, options.merge(as: :text)) + template.content_tag("alchemy-tinymce", text_area) + end + # Renders a button tag wrapped in a div with 'submit' class. # def submit(label, options = {}) diff --git a/spec/libraries/forms/builder_spec.rb b/spec/libraries/forms/builder_spec.rb index dd7bb5654d..d4f8e705ca 100644 --- a/spec/libraries/forms/builder_spec.rb +++ b/spec/libraries/forms/builder_spec.rb @@ -26,21 +26,21 @@ end end - let(:template) do - double( - "Template", - controller: controller, - label: "