New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails 4.2 text_field issue #620

Closed
ghost opened this Issue Dec 24, 2014 · 12 comments

Comments

Projects
None yet
@ghost

ghost commented Dec 24, 2014

Hi. I'm using ruby 2.1.5 and recently upgraded to rails 4.2. I noticed ActionView::Helpers::Tags::TextField no longer calls html_safe on its value, which means that for a post with tag_list ['ruby', 'rails'], the following erb block
<%= f.text_field :tag_list %>
produces
<input type="text" value="ruby rails" name="post[tag_list]" id="post_tag_list">
rather than
<input type="text" value="ruby, rails" name="post[tag_list]" id="post_tag_list">

It's easily fixed by
<%= f.text_field :tag_list, value: @post.tag_list.to_s %>
but I was wondering if there's a way to go about this issue without having to specify the value option each time?

@seuros

This comment has been minimized.

Show comment
Hide comment
@seuros

seuros Dec 24, 2014

Collaborator

Yes, this is by design for security reasons.
But we could add an option to html safe the tags by default.

Collaborator

seuros commented Dec 24, 2014

Yes, this is by design for security reasons.
But we could add an option to html safe the tags by default.

@DaniG2k

This comment has been minimized.

Show comment
Hide comment
@DaniG2k

DaniG2k Dec 25, 2014

It would be nice, yes. Right now I am also forced to do:

<%= f.label tag.to_s.titleize %>
<% tag_sym = "#{tag.to_s.singularize}_list".to_sym %>
<% tag_list = "#{tag.to_s.singularize}_list" %>
<%= f.text_field tag_sym, value: @article.send(tag_list).to_s, :placeholder => "Comma-separated list of #{tag.to_s}", class: 'form-control' %>

Note: I asked this on StackOverflow as well 😦

DaniG2k commented Dec 25, 2014

It would be nice, yes. Right now I am also forced to do:

<%= f.label tag.to_s.titleize %>
<% tag_sym = "#{tag.to_s.singularize}_list".to_sym %>
<% tag_list = "#{tag.to_s.singularize}_list" %>
<%= f.text_field tag_sym, value: @article.send(tag_list).to_s, :placeholder => "Comma-separated list of #{tag.to_s}", class: 'form-control' %>

Note: I asked this on StackOverflow as well 😦

@bf4

This comment has been minimized.

Show comment
Hide comment
@bf4

bf4 Dec 25, 2014

Collaborator

The best option might be to make a custom input for the form builder

Collaborator

bf4 commented Dec 25, 2014

The best option might be to make a custom input for the form builder

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Dec 27, 2014

Seems like the easiest way is to make a custom tag_list_field where the input type defaults to text or can be specified. Thanks for the help!

ghost commented Dec 27, 2014

Seems like the easiest way is to make a custom tag_list_field where the input type defaults to text or can be specified. Thanks for the help!

@ghost ghost closed this Dec 27, 2014

@lenart

This comment has been minimized.

Show comment
Hide comment
@lenart

lenart Jan 21, 2015

Not being able to use Rails' form helpers "out of the box" feels a bit weird to me as well.

Could @seuros or @bf4 explain why you decided to take this approach? You mentioned security but I'd like to understand this better.

lenart commented Jan 21, 2015

Not being able to use Rails' form helpers "out of the box" feels a bit weird to me as well.

Could @seuros or @bf4 explain why you decided to take this approach? You mentioned security but I'd like to understand this better.

jgarber623 added a commit to FrancisCMS/FrancisCMS that referenced this issue Jan 23, 2015

@stiff

This comment has been minimized.

Show comment
Hide comment
@stiff

stiff Feb 13, 2015

Contributor

Maybe just add glued_tags and glued_tags= to use in forms?

Contributor

stiff commented Feb 13, 2015

Maybe just add glued_tags and glued_tags= to use in forms?

@openscript

This comment has been minimized.

Show comment
Hide comment
@openscript

openscript Feb 22, 2015

What kind of security feature are you talking about?

openscript commented Feb 22, 2015

What kind of security feature are you talking about?

@usutani usutani referenced this issue May 1, 2015

Closed

Rails 4.2対応 #1

2 of 2 tasks complete
@tirdadc

This comment has been minimized.

Show comment
Hide comment
@tirdadc

tirdadc May 11, 2015

Why was this closed when no explanation for this change was provided?

tirdadc commented May 11, 2015

Why was this closed when no explanation for this change was provided?

@ScotterC

This comment has been minimized.

Show comment
Hide comment
@ScotterC

ScotterC May 12, 2015

This should be noted in a changelog somewhere because on upgrade to 4.2 I had some production projects lose tag data because when the resources were saved again the commas were lost and it created new tags.

ScotterC commented May 12, 2015

This should be noted in a changelog somewhere because on upgrade to 4.2 I had some production projects lose tag data because when the resources were saved again the commas were lost and it created new tags.

@AlexVPopov

This comment has been minimized.

Show comment
Hide comment
@AlexVPopov

AlexVPopov Jul 28, 2015

Contributor

Created a wiki-page, addressing this issue.

Contributor

AlexVPopov commented Jul 28, 2015

Created a wiki-page, addressing this issue.

@carlflor

This comment has been minimized.

Show comment
Hide comment
@carlflor

carlflor Aug 12, 2015

For simple_form it's like this:

<%= f.input :tag_list, input_html: {value: @something.tag_list.to_s} %>

carlflor commented Aug 12, 2015

For simple_form it's like this:

<%= f.input :tag_list, input_html: {value: @something.tag_list.to_s} %>

tjgrathwell added a commit to pivotal-legacy/projectmonitor that referenced this issue Apr 22, 2016

@korny

This comment has been minimized.

Show comment
Hide comment
@korny

korny Jan 12, 2018

This was our solution:

module ActionView::Helpers::TagHelper
  private
  def tag_option_with_tag_list_support(key, value, escape)
    if value.is_a?(ActsAsTaggableOn::TagList)
      value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s
    end

    tag_option_without_tag_list_support key, value, escape
  end
  alias_method_chain :tag_option, :tag_list_support
end

korny commented Jan 12, 2018

This was our solution:

module ActionView::Helpers::TagHelper
  private
  def tag_option_with_tag_list_support(key, value, escape)
    if value.is_a?(ActsAsTaggableOn::TagList)
      value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s
    end

    tag_option_without_tag_list_support key, value, escape
  end
  alias_method_chain :tag_option, :tag_list_support
end

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment