Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails best_in_place gem while clicking on the label name

I am using the best in place gem - which is great. Only thing is that I want the user to be able to click not just the best in place element in order to edit it, but also the label. Lets say I have this best in place element:

<b>Open Hours</b>
<%= best_in_place @provider, :open_hours, :type => :select, :collection => Provider::PROVIDERS_HOURS %>

I want to be able to click the Open Hours in order to open the edit element. Is it possible?

Thanks

like image 540
user1666543 Avatar asked Feb 19 '23 00:02

user1666543


2 Answers

For single instance of a class you can simply

<b id='edit-open-hours'>Open Hours</b>
<%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-open-hours' %>

If you want to do this with a list view you will need to make each id-identifier unique with an ID

<b id='edit-<%= @provider.id %>'>Open Hours</b>
<%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-' + @provider.id.to_s %>
like image 69
Elan P Avatar answered Mar 03 '23 16:03

Elan P


This was very helpful, but a small correction: you have to prefix the activator DOM element with the relevant symbol (# for id, . for class).

So the second example would be

<%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-' + @provider.id.to_s %>
like image 38
user2261892 Avatar answered Mar 03 '23 17:03

user2261892