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 571 forks source link

activator not working for checkbox #471

Closed dynamicworkplace closed 9 years ago

dynamicworkplace commented 9 years ago

Rails 4.2.1, best_in_place 3.0.3

I'm having problems with the activator not working for checkboxes - it works for other field types.

    <div class="col-md-2">
      Play instrument:
      <span id='edit_play_instrument' class="glyphicon glyphicon-pencil text-primary"></span>
    </div>
    <div class="col-md-3">
      <div class='input-group-lg'>
        <%= best_in_place @host_family, :play_instrument, as: :checkbox, activator: '#edit_play_instrument' %>
      </div>
    </div>

I'd be grateful for your advice on whether this is an issue in this version, or help diagnosing the fault.

Thank you

stereodenis commented 9 years ago

@dynamicworkplace could you provide a sample app with this issue?

dynamicworkplace commented 9 years ago

I've investigated this further and the activator is working and toggles the boolean data, however the display isn't refreshing to Yes/No - other fields are redisplaying correctly after being updated.

stevobengtson commented 9 years ago

I can confirm the same issue, the Yes/No values are not being updated after a successful change. Clicking on Yes or No updates the database, however the text remains the same.

Model: PendingInvite approved: boolean

view: <%= best_in_place pending_invite, :approved, as: :checkbox %>

controller:

PATCH/PUT /pending_invites/1

PATCH/PUT /pending_invites/1.json

def update @pending_invite = PendingInvite.find(params[:id]) respond_to do |format| if @pending_invite.update(pending_invite_params) format.html { redirect_to @pending_invite, notice: 'Pending invite was successfully updated.' } format.json { respond_with_bip(@pending_invite) } else format.html { render :edit } format.json { respond_with_bip(@pending_invite) } end end end

dynamicworkplace commented 9 years ago

I tried using a display_with method and this will display the data correctly after an update, though it doesn't use the method when the data is first displayed.

stereodenis commented 9 years ago

@stevobengtson @dynamicworkplace are you using the latest version from github?

dynamicworkplace commented 9 years ago

Using best_in_place 3.0.3 from https://github.com/bernat/best_in_place.git (at master)

stereodenis commented 9 years ago

@dynamicworkplace make a sample repo with this bug and I will try to check it

stevobengtson commented 9 years ago

@stereodenis I have set up a test repository that duplicates the issue, and have come across something helpful.

https://github.com/stevobengtson/bip_test

In this test navigate to http://localhost:3000/inventories I have added bip to the table. Clicking on entries in the used column will update the data but not update the display (refresh page to see changes), however clicking on the stored column will update the display instantly (no refresh required).

The difference is that Used is setup with the default "No", "Yes" collection, where as the Stored is setup with the hash syntax { false: "No", true: "Yes"}. So it looks like when the collection is an array it fails to update.

Using the select with an array collection (see Location) works as expected.

Hope this helps :).

MrHubble commented 9 years ago

Thanks @stevobengtson , changing my collection from collection: %w[No Yes] % to collection: { false: "No", true: "Yes"} fixed the issue for me.