-
Notifications
You must be signed in to change notification settings - Fork 573
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
When using :display_with shows text AND nil value. Only allows editing of nil value. #331
Comments
Which version of Rails are you using? |
Ruby: 2.0.0p353 |
I am getting the same error. When I use (display_with: :simple_format) I get both the nil text and the saved attribute |
Changing the best_in_place helper method so that it wraps the markup it generates into a div instead of a span fixed this for me. I used :display_as with a textile field rendered as html, and I noticed that calling jQuery's html() method on a span with a tag inside of it resulted in nil getting returned, which then got interpreted by BIP to display :nil. The jQuery html() nil is probably due to a tag inside of a tag being regarded as invalid HTML 5. |
Can you send a PR ? |
@bensaufley , @pjmartorell, @vjt , @the-robear , @sao, @outomyelement : what do you thinkg about changing it to div ? |
` in a `` is invalid HTML, yes. What if we had an option for it? |
👍 for the container: :div. We could also make it better by have the gem configurable #initializers/best_in_place.rb
BestInplace.configure do |config|
config.container = :div
end |
That's a great idea. I can tackle the |
I can do the configure part. I will do it asap, since your task depend on mine. it will consist mostly in writing some specs. What worry me about this gem, is the thread safety issue with display_* . I think we have to find another event if that break the api. |
To reproduce the issue
|
But that's a known issue, right, even in master? |
Yes, it was here since the introduction of display_as, 2 year ago. I noticed that while reading the code. |
Yeah. So, definitely a concern but not something blocking from merging, fixing, updating other things. |
Yep. we could do it in version 3.1 |
I tried to use display_as on an attribute in my model that contains Textile formatted html. Textile wraps all of it's content in p tags. P tags inside of a span is invalid HTML, span is an inline element and therefore you can't have block-level elements (such as a p, div, h1, table etc.), inside of a span. When best_in_place uses element.html(), it's receiving a nil because, I suspect, the invalid HTML is not available to the DOM and thus not available to be inspected by jQuery. On lines 42 and 75 of https://github.com/bernat/best_in_place/blob/master/lib/best_in_place/helper.rb, I changed the span to a div, because div's can hold other block-level elements. I forked the repo and tried running the specs but I got lost at the part on cding into test_app. I couldn't find the test_app dir in the codebase so I have no idea if this breaks anything except to say that so far it's working quite dandy for me and I've already sent the change to my production environment. |
@bensaufley @seuros I agree on the content param 👍 |
I pushed the configure part
You can also use the block syntax when we will add other options. We need test for the js. |
Hi, is there any progress on this being fixed? i.e. Is it on the roadmap? The ability to be able to render carriage returns etc in textareas is a pretty common requirement I would imagine. |
@seuros display_with (; |
I have the following code:
<%= best_in_place_if can?(:update, risk), risk, :effect, :display_with => :simple_format, :path => assessment_risk_path(assessment,risk), type: :textarea, html_attrs: { "class" => "input-block-level" }, :nil => "Click to add a effect..." %>
What I get on screen is
The attribute's text is correctly formatted, but:
Any ideas?
The text was updated successfully, but these errors were encountered: