best_in_place
best_in_place copied to clipboard
bip select box not working
I'm having an issue where best in place select boxes aren't displaying. We have a large project with react_on_rails and Materialize installed. I'm not sure if one of those 2 things are messing with the select box. All other BIP forms are working corrrectly. Here's my code for my select box...
<%= best_in_place @organization, :default_social_feed, as: :select, collection: %w(Facebook Twitter)>
It displays on the view as just a -
. Inspecting this dash shows the following...
<span data-bip-type="select" data-bip-attribute="name" data-bip-collection="[[1,"Facebook"],[2,"Twitter"]]" data-bip-object="organization" data-bip-original-content="Ohio Ballstars" data-bip-skip-blur="false" data-bip-url="/admin/organizations/1" data-bip-value="Ohio Ballstars" class="best_in_place bip-placeholder" id="best_in_place_organization_1_name">
-
</span>
If I click the -
on the view, it changes the html to the following...
<span data-bip-type="select" data-bip-attribute="name" data-bip-collection="[[1,"Facebook"],[2,"Twitter"]]" data-bip-object="organization" data-bip-original-content="Ohio Ballstars" data-bip-skip-blur="false" data-bip-url="/admin/organizations/1" data-bip-value="Ohio Ballstars" class="best_in_place bip-placeholder" id="best_in_place_organization_1_name">
<form action="javascript:void(0)" style="display:inline">
<select>
<option value="1">Facebook</option>
<option value="2">Twitter</option>
</select>
</form>
</span>
The -
then goes away. No select box ever appears. I also can't find any conflicting CSS code that might be causing problems.
Any ideas?
Thanks, Nick
This might be a duplicate of issue #404 Do you get any errors on the browser console output?
Was this ever figured out? I am trying to fix this now
fwiw, i am having the same issue... any hint is highly appreciated.
in the view:
<%= best_in_place_if(policy(@tradeplan).edit?, @tradeplan, :instrument, as: :select, collection: Instrument.all.order(:id).map { |i| [i.id, i.symbol] }, display_as: :symbol) %>
the collection:
irb(main):004:0> Instrument.all.order(:id).map { |i| [i.id, i.symbol] } Instrument Load (0.4ms) SELECT "instruments".* FROM "instruments" ORDER BY "instruments"."id" ASC => [[1, "ES"], [2, "NQ"], [3, "RTY"], [4, "YM"]]
the model method:
def symbol self.instrument.symbol end
thanks, Andreas
i think i've found it - at least for my use case...
:instrument is referring to an association introduced by belongs_to in the model... the proper attribute is :instrument_id, though..
no wonder it cant map an association to an array of id's and (in my case) symbols...
so, changing the view to:
<%= best_in_place_if(policy(@tradeplan).edit?, @tradeplan, :instrument_id, as: :select, collection: Instrument.all.order(:id).map { |i| [i.id, i.symbol] }, display_as: :symbol) %>
does the trick..
hope this helps, Andreas