Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[32501] Make long test CF creation form show WYSIWYG editor

Oliver Günther459c8414c001
diff --git a/app/assets/javascripts/custom-fields.js b/app/assets/javascripts/custom-fields.js
index 18a291ece94..a8dbcae2536 100644
--- a/app/assets/javascripts/custom-fields.js
+++ b/app/assets/javascripts/custom-fields.js
@@ -44,6 +44,7 @@
possibleValues = $('#custom_field_possible_values_attributes'),
defaultValueFields = $('#custom_field_default_value_attributes'),
spanDefaultText = $('#default_value_text'),
+ spanDefaultLongText = $('#default_value_long_text'),
spanDefaultBool = $('#default_value_bool'),
textOrientationField = $('#custom_field_text_orientation');
@@ -66,10 +67,10 @@
unsearchable = function() { searchable.attr('checked', false).hide(); };
// defaults (reset these fields before doing anything else)
- $.each([spanDefaultBool, spanDefaultText, multiSelect, textOrientationField], function(idx, element) {
+ $.each([spanDefaultBool, spanDefaultLongText, spanDefaultText, multiSelect, textOrientationField], function(idx, element) {
deactivate(element);
});
- show(defaultValueFields);
+ activate(defaultValueFields);
activate(spanDefaultText);
switch (format.val()) {
@@ -109,6 +110,8 @@
unsearchable();
break;
case 'text':
+ activate(spanDefaultLongText);
+ deactivate(spanDefaultText);
show(lengthField, regexpField, searchable, textOrientationField);
deactivate(possibleValues);
activate(textOrientationField);
@@ -122,6 +125,7 @@
// assign the switch format function to the select field
format.on('change', toggleFormat).trigger('change');
+ toggleFormat();
});
$(function() {
diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb
index 534c5576c5f..31cedbe80cb 100644
--- a/app/views/custom_fields/_form.html.erb
+++ b/app/views/custom_fields/_form.html.erb
@@ -87,15 +87,31 @@ See docs/COPYRIGHT.rdoc for more details.
<% end %>
<div id="custom_field_default_value_attributes">
<div class="form--field" id="default_value_text">
- <% if @custom_field.new_record? || @custom_field.field_format != 'bool' %>
- <%= f.text_field(:default_value, container_class: '-wide') %>
+ <% if @custom_field.new_record? || !%w[text bool].include?(@custom_field.field_format) %>
+ <%= f.text_field :default_value,
+ id: 'custom_fields_default_value_text',
+ for: 'custom_fields_default_value_text',
+ container_class: '-wide' %>
<% end %>
</div>
<div class="form--field" style="display:none" id="default_value_bool">
<% if @custom_field.new_record? || @custom_field.field_format == 'bool' %>
- <%= f.check_box(:default_value) %>
+ <%= f.check_box :default_value,
+ id: 'custom_fields_default_value_bool',
+ for: 'custom_fields_default_value_bool' %>
<% end %>
</div>
+ <div class="form--field" style="display:none" id="default_value_long_text">
+ <% if @custom_field.new_record? || @custom_field.field_format == 'text' %>
+ <%= f.text_area :default_value,
+ id: 'custom_fields_default_value_longtext',
+ for: 'custom_fields_default_value_longtext',
+ cols: 100,
+ rows: 20,
+ class: 'wiki-edit',
+ with_text_formatting: true %>
+ <% end %>
+ </div>
</div>
<%= call_hook(:view_custom_fields_form_upper_box, custom_field: @custom_field, form: f) %>
</section>
diff --git a/spec/features/custom_fields/create_long_text_spec.rb b/spec/features/custom_fields/create_long_text_spec.rb
new file mode 100644
index 00000000000..eb795daafcd
--- /dev/null
+++ b/spec/features/custom_fields/create_long_text_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+require 'support/pages/custom_fields'
+
+describe 'custom fields', js: true do
+ let(:user) { FactoryBot.create :admin }
+ let(:cf_page) { Pages::CustomFields.new }
+ let(:editor) { ::Components::WysiwygEditor.new '#default_value_long_text' }
+ let(:type) { FactoryBot.create :type_task }
+ let(:project) { FactoryBot.create :project, enabled_module_names: %i[work_package_tracking], types: [type] }
+
+ let(:wp_page) { Pages::FullWorkPackageCreate.new project: project }
+
+ let(:default_text) do
+ <<~MARKDOWN
+ # This is an exemplary test
+
+ **Foo bar**
+
+ MARKDOWN
+ end
+
+ before do
+ login_as(user)
+ end
+
+ describe "creating a new long text custom field" do
+ before do
+ cf_page.visit!
+ click_on "Create a new custom field"
+ end
+
+ it "creates a new bool custom field" do
+ cf_page.set_name "New Field"
+ cf_page.select_format "Long text"
+
+ sleep 1
+
+ editor.set_markdown default_text
+
+ cf_page.set_all_projects true
+ click_on "Save"
+
+ expect(page).to have_text("Successful creation")
+ expect(page).to have_text("New Field")
+
+ cf = CustomField.last
+ expect(cf.field_format).to eq 'text'
+
+ # textareas get carriage returns entered
+ expect(cf.default_value.gsub("\r\n", "\n").strip).to eq default_text.strip
+
+ type.custom_fields << cf
+ type.save!
+
+
+ wp_page.visit!
+ wp_editor = TextEditorField.new(page, 'description', selector: ".inline-edit--container.customField#{cf.id}")
+ wp_editor.expect_active!
+
+ wp_editor.ckeditor.in_editor do |container, _|
+ expect(container).to have_selector('h1', text: 'This is an exemplary test')
+ expect(container).to have_selector('strong', text: 'Foo bar')
+ end
+ end
+ end
+end
diff --git a/spec/support/pages/custom_fields.rb b/spec/support/pages/custom_fields.rb
index e6840a17b56..a7efbf48101 100644
--- a/spec/support/pages/custom_fields.rb
+++ b/spec/support/pages/custom_fields.rb
@@ -43,7 +43,11 @@ module Pages
end
def set_default_value(value)
- find("#custom_field_default_value").set value
+ fill_in 'custom_field[default_value]', with: value
+ end
+
+ def set_all_projects(value)
+ find('#custom_field_is_for_all').set value
end
def has_form_element?(name)