Top Menu

Jump to content
Home
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Calendars
    Calendars
  • Team planners
    Team planners
  • Boards
    Boards
  • News
  • Forums

Content

Development
  1. OpenProject
  2. Forums
  3. Development
  4. Bug Fix on Custom Fields

Bug Fix on Custom Fields

Added by jason southwell over 11 years ago

In the 3 beta dev branch, the custom_fields_helper.rb file has a bug

the code:

    when "list"
      blank_option = custom_field.is_required? ?
                       (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>".html_safe : '') :
                       '<option></option>'.html_safe
      select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id)

should be:

    when "list"
      blank_option = custom_field.is_required? ?
                       (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>".html_safe : '') :
                       '<option></option>'.html_safe
      select_tag(field_name, (blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value)).html_safe, :id => field_id)

This fixes the problem where the options in a list type Custom Field are rendered to the browser as a string rather than html Option tags.


Replies (9)

RE: Bug Fix on Custom Fields - Added by Jens Ulferts over 11 years ago

Hi Jason,

thanks for the hint.

As of yet I have been unable to find a screen which displays html tags for list custom fields where a drop down should be rendered.

Can you please point me to one?

Best

Jens

RE: Bug Fix on Custom Fields - Added by jason southwell over 11 years ago

Sorry if I wasn’t clear. The problem wasn’t that html tags would be visibly displayed, but that the option tags were rendered as strings instead of option tags. Specifically where you see the problem is if you have a custom field for a work package that is of type list and you add many list items. Then when you go to create a new work package, the drop down is rendered but with no items. If you look at the source, the looks something like this:

<select id="work_package_custom_field_values_10" name="work_package[custom_field_values][10]">&lt;option value="High"&gt'High&lt;/option&gt;%lt;option value="Low"&gt;Low&lt;/option&gt;</select>

RE: Bug Fix on Custom Fields - Added by Jens Ulferts over 11 years ago

Thanks for clarifying. Now I’ve got it. It took me some time because there is only a bug when the custom field has a non empty default value. So the html_safe is missing on the blank_option in those awfully nested ternary if statement:

when "list" 
      blank_option = custom_field.is_required? ?
                       (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>".html_safe : ''.html_safe) :
                       '<option></option>'.html_safe
      select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id)

or to have less html_safe in there:

when "list" 
      blank_option = custom_field.is_required? ?
                       (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
                       '<option></option>'

      select_tag(field_name, blank_option.html_safe + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id)

which after some refactoring could be this:

      blank_option = if custom_field.is_required? && custom_field.default_value.blank?
                       "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>"
                     elsif custom_field.is_required? && !custom_field.default_value.blank?
                       ''
                     else
                       '<option></option>'
                     end

      options = blank_option.html_safe + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value)

      select_tag(field_name, options, :id => field_id)

I opened up a bug for that:

Care to provide a pull request for that? I wouldn’t want to steal your work.

RE: Bug Fix on Custom Fields - Added by jason southwell over 11 years ago

The work is yours to steal.

On another note, there is a link to a contributor agreement for me to sign before I’m supposed to start contributing but it appears to not actually exist. Is there an agreement that you want signed or should we just start contributing as we see fit?

RE: Bug Fix on Custom Fields - Added by Birthe Lindenthal over 11 years ago

Hi Jason,

yes, in deed, there is a Contributor Agreement to clarifiy your rights to use your own contributions. I will send it to you via email.
Cheers,
Birthe

RE: Bug Fix on Custom Fields - Added by Philipp Tessenow over 11 years ago

Just out of curiosity: Birthe, why don’t we upload that agreement and link to it instead of sending a mail to everyone?

RE: Bug Fix on Custom Fields - Added by Birthe Lindenthal over 11 years ago

We can do so as well. I was just waiting for http://development.contributoragreements.org/ to finish their individual CLA. However, it seems that it’s better to publish our own version.

RE: Bug Fix on Custom Fields - Added by Jens Ulferts over 11 years ago

Issued a PR, so that should be fixed soon. Thanks again.

RE: Bug Fix on Custom Fields - Added by Jens Ulferts about 11 years ago

The PR got merged, so it is now part of the dev branch.

  • (1 - 9/9)
Loading...