Defect #31896

Admin screen - "New custom field" button does not work if there are no custom fields

Added by Neville Kuyt over 2 years ago. Updated over 2 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Administration
Target version:-
Resolution:Fixed Affected version:

Description

New install of Redmine.

Log in as an administrator.
Go to "administrattion" tab, then select "custom fields".

Click on "New custom field".
Expected: New custom field form shows.
Actual: nothing happens.

Cause: the "New custom field" link includes some JavaScript to figure out which tab is selected; it uses this to figure out the "onclick" action. When there are no custom fields, there are no tabs, and therefore the JavaScript fails to generate a valid URL for the onclick.

Environment:
Redmine version 4.0.4.devel
Ruby version 2.3.7-p456 (2018-03-28) [universal.x86_64-darwin18]
Rails version 5.2.3
Environment development
Database adapter SQLite
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
SCM:
Subversion 1.10.3
Git 2.19.0
Filesystem
Redmine plugins:
no plugin installed


Related issues

Related to Redmine - Patch #31320: Set an appropriate default type in New custom field page ... Closed

Associated revisions

Revision 18372
Added by Go MAEDA over 2 years ago

Fix that "New custom field" button does not work if there are no custom fields (#31896, #31320).

Patch by Mizuki ISHIKAWA.

History

#1 Updated by Marius BALTEANU over 2 years ago

  • Status changed from New to Confirmed

Caused by #31320

#2 Updated by Marius BALTEANU over 2 years ago

  • Related to Patch #31320: Set an appropriate default type in New custom field page depending on the current tab added

#3 Updated by Mizuki ISHIKAWA over 2 years ago

Thank you for sharing this issue.
The changes below should make the "New custom field" link work.

diff --git a/app/views/custom_fields/index.html.erb b/app/views/custom_fields/index.html.erb
index 3f1154dc7..0eecc6014 100644
--- a/app/views/custom_fields/index.html.erb
+++ b/app/views/custom_fields/index.html.erb
@@ -1,5 +1,5 @@
 <div class="contextual">
-<%= link_to_function l(:label_custom_field_new), "location.href = '#{new_custom_field_path}?tab=' + encodeURIComponent($('.tabs a.selected').attr('id').split('tab-').pop())", :class => 'icon icon-add' %>
+<%= link_to_function l(:label_custom_field_new), "location.href = '#{new_custom_field_path}?tab=' + encodeURIComponent(($('.tabs a.selected').attr('id')||'').split('tab-').pop())", :class => 'icon icon-add' %>
 </div>

 <%= title l(:label_custom_field_plural) %>

#4 Updated by Neville Kuyt over 2 years ago

Mizuki ISHIKAWA wrote:

Thank you for sharing this issue.
The changes below should make the "New custom field" link work.

[...]

Tested - yes, this fixes it. Thank you!

#5 Updated by Go MAEDA over 2 years ago

  • Status changed from Confirmed to Closed
  • Resolution set to Fixed
  • Affected version deleted (4.0.4)

Committed the fix. Thank you all for reporting and fixing this issue.

Also available in: Atom PDF