bernat / best_in_place

A RESTful unobtrusive jQuery Inplace-Editor and a helper as a Rails Gem
http://blog.bernatfarrero.com/in-place-editing-with-javascript-jquery-and-rails-3/
1.2k stars 574 forks source link

:display_with is not being used when rendering :as=>:select #569

Open vanboom opened 7 years ago

vanboom commented 7 years ago

I have a BIP select that is based on an enum set and am trying to apply a class to the render to show inactive records in RED:

= best_in_place customer, :status, :as=>:select, :collection=>... , :display_with=> ->(c){format_customer_status(c)}

When the page is rendered initially, the display_with function is not called. I have confirmed that the helper proc is being called, however the rendered content_tag is not being sent to the view, only the attribute value.

If the status is changed using the BIP select, the new status renders perfectly.

vanboom commented 7 years ago

UPDATE: there is some mismatch between the way BIP renders the initial value in the best_in_place method vs. rendering the value on select.
Offending line 25 in helper.rb:

display_value = collection.flat_map{|a| a[0].to_s == value ? a[1] : nil }.compact[0]

This line sets the initial display value using the collection values, but does not use display_with or display_as