Open link in a new tab

Content

Expand project menu

Bug Fix on Custom Fields

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.

Message actions

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

Message actions

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>
Message actions

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.

Message actions

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?

Message actions

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

Message actions

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

Message actions

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.

Message actions

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

Message actions

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