Patch #40210
closedRemove overrides that inserts a non-breaking space (nbsp) to empty option elements
0%
Description
In Redmine forms, a problem occurs where the "blank" option does not appear in select box fields (e.g., Version or Category). The blank option is visible when the default value is blank, such as in the new issue form. However, if a non-blank value is selected, saved, and then the edit issue form is reloaded, the blank option is missing from the select box.
Example 1: After changing the category value from blank to another value and registering the issue, when you attempt to change the category back to blank in the edit form, the blank option is missing from the category select box.
Example 2: Similarly, when creating a new issue with a default version set in the project settings, if you try to set the version back to blank, the blank option is missing from the version select box.
Despite the f.selectbox being configured with include_blank: true, it does not seem to function properly. This issue does not occur in the Redmine 5.1-stable version and is observed only in the trunk version.
Files
Related issues
Updated by Go MAEDA 10 months ago
- File clipboard-202402081626-rfc6i.png clipboard-202402081626-rfc6i.png added
- Status changed from New to Confirmed
I have confirmed the issue. In the following screenshot, you cannot set the assignee field to blank.
Updated by Mizuki ISHIKAWA 10 months ago
It appears to be affected by the changes made to config/initializers/10-patches.rb in r22488 ( https://github.com/redmine/redmine/commit/7b911245d31509da8fa656bbedc37213d3148897?diff=unified&w=0#diff-3df1b8f50fcd1f2fcef72d0bae0d030cc1c5dad45c63acbd1722b4c6fa98c7f6R55-L83 ) .
The problem can be fixed by making the following change.
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index 1d932eb1f..6024e8c8d 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -41,7 +41,7 @@ module ActionView
SelectRenderer.prepend(Module.new do
def add_options(option_tags, options, value = nil)
if options.delete(:include_blank)
- options[:prompt] = ' '.html_safe
+ options[:include_blank] = ' '.html_safe
end
super
end
Updated by Go MAEDA 10 months ago
- Related to Feature #36320: Migrate to Rails 7.2 added
Updated by Go MAEDA 10 months ago
- File dont-insert-nbsp-to-blank-option-element.patch dont-insert-nbsp-to-blank-option-element.patch added
I am beginning to question the necessity of the code that inserts a non-breaking space (nbsp
) to empty option elements.
The code was added in r12237. The purpose of the change was to fix HTML5 validation failures pointed out in #15191. However, I have not found any evidence that empty option elements violate HTML5 standards.
I tested the following HTML, which contains an empty option element (<option value="" label=" "></option>
), using the Nu Html Checker by W3C and the test passed without any errors.
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<select name="issue[category_id]" id="issue_category_id"><option value="" label=" "></option>
<option selected="selected" value="1">Printing</option>
<option value="2">Recipes</option></select>
</body>
</html>
Additionally, I checked the MDN documentation and still could not find any mention of an empty option element being prohibited.
I believe the Rails team should have improved the form helper to insert nbsp
when :include_blank
is passed if it violates HTML5 standards, but such enhancement has not occured even 10 years after r12237 was committed. In my opinion, this suggests that the Rails team does not consider empty option elements are disallowed.
Based on the above, I propose to delete the code to insert nbsp to every blank option element.
Updated by Mizuki ISHIKAWA 10 months ago
Based on the above, I propose to delete the code to insert nbsp to every blank option element.
I'm in favor of it.
Updated by Marius BĂLTEANU 10 months ago
- Tracker changed from Defect to Patch
- Subject changed from Blank option not included in selectbox options when a non-blank value is selected to Remove overrides that inserts a non-breaking space (nbsp) to empty option elements
- Category set to Code cleanup/refactoring
- Status changed from Confirmed to Resolved
- Target version set to 6.0.0
Updated by Go MAEDA 10 months ago
- Related to Defect #25337: Redmine patch for Rails breaks functionality of select_tag added