best_in_place show dropdown menu option

1.1k Views Asked by At

I figured that this would be a common need, but have been unsuccessful in finding a solution. I followed this ASCIIcast by Ryan Bates http://railscasts.com/episodes/302-in-place-editing?view=asciicast and now have functional in place editing on my website. However, I think it is not intuitive that these records are editable at all, as they just appear as a plain text representation of the current record value until you click them. I want something so that the select dropdown shows up by default like it would in a normal form as shown in the image. Is there anyway to do this using best_in_place or rest_in_place? I would like to have this show all the time

3

There are 3 best solutions below

0
On

I know it is not exactly the answer you are looking for but you can style the best_in_place values using the .best_in_place class.

I did something like this on my website, which helps showing that the value is editable:

.best_in_place {
    padding-right: 18px;
    background-image: url('*/ link to an edit icon /*');
    background-size: 15px auto;
    background-position: right center;
    background-repeat: no-repeat;
    cursor: pointer;
}

.best_in_place:hover {
  background-color:#eeeeee;
}
1
On

What i think you want to do is to find the styles that are applied to the hover state of the element, and copy them to the normal state of the element too.

In chrome inspector:

  • Right click on the select tag and choose "Inspect element"
  • Right click on the element as seen in the "Elements" tab and choose "Force element state" and then "hover"

On the right of the inspector now you should see the styles that are applied to the :hover state of the element. Copy these into your stylesheet and remove the ":hover" part from the end of the rule. You might need to add some extra selectors to the rule to make sure you don't do this for all selects across your entire site.

0
On

A dropdown is the default behavior for best_in_place if your original form input is via radio buttons. Otherwise, you can use a :colllection to at least validate the new data entry. e.g. in haml, updated answer must be red, green or blue:

.flex1=best_in_place :color, :type => :select, :collection => (["red","blue","green"])