Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Multiple Fields #57

Closed
zacksiri opened this issue Dec 15, 2011 · 10 comments
Closed

Update Multiple Fields #57

zacksiri opened this issue Dec 15, 2011 · 10 comments

Comments

@zacksiri
Copy link

Was wondering if you have any plans to support multiple fields update.

as in for example

i have a field called unit_price
and a field called quantity
and another field called total

displayed in a row.

I want it to be such that if I update the quantity and on the server side i have a call back function that updates the total when we re display the data it actually updates the 'total' display field as well?

@zacksiri
Copy link
Author

perhaps we could do something like this

<%= best_in_place @blah, :field, update_multiple: [[:total], [:whatever]] %>

@imginit
Copy link

imginit commented Dec 16, 2011

This would be extremely helpful, +1

@taavo
Copy link

taavo commented Dec 18, 2011

Can you confirm this isn't already possible by handling the ajax:success event?

@zacksiri
Copy link
Author

where would we but the ajax:success? i mean if you have lots of fields you'll be managing a lot of it. it would be nicer to have some kind of way to do it from best_in_place

@RavWar
Copy link

RavWar commented Dec 20, 2011

I can confirm. Here's a simple example using jquery:

$('.best_in_place').change(function() {
  $.ajax({
    success: function() {

    }
  });
});

@RavWar
Copy link

RavWar commented Dec 21, 2011

artellectual, i had the exact same problem: price, quantity, sum displayed in a row and below the table total price of all products, user can change quantity and sum with total price should be updated.
I did it like this:
Moved my order information into a partial, created new route
get 'order_sum', :controller => 'orders', :action => :order_sum
Added this action to a controller to display partial

def order_sum
  render :partial => 'shared/order_sum'
end

Then i add jquery

$('.best_in_place').change(function() {
  $.ajax({
    success: function() {
      $('.order_product_sum').load('/order_sum');
    }
  });
});

But i have a problem with displaying information. Firstly, i wanted to make that only column with sums is in partial and gets updated. But i havent figured out how to display it properly. I tried to move the whole table into partial and when u use it for the first time - everything loads up perfectly, but then best_in_place stops working...

@RavWar
Copy link

RavWar commented Dec 21, 2011

The solution to broken best_in_place after loading the whole table was pretty easy

$('.best_in_place').change(function() {
  $.ajax({
    success: function() {
      $('.order_product_sum').load('/order_sum', function(){
        $('.best_in_place').best_in_place();
      });
    }
  });
});

@zacksiri
Copy link
Author

its not the cleanest solution though, you have to create a custom order_sum action. when you update the object using best_in_place it returns the json data anyway it should update the field using that new data, instead of loading the data twice.

@VonD
Copy link

VonD commented Dec 26, 2011

Hi everyone,

I've tried to implement this on my fork of the project, on the update_with branch : https://github.com/VonD/best_in_place
I haven't wrote tests for it yet, but it works fine on my app.
Can you please have a look at it and tell me what you think ?
Please make all comments as it is the first time i put my hands on a gem.
The docs are updated, but here is the syntax :

= best_in_place object, field, :update_with => :other_field

Or

= best_in_place object, field, :update_with => [:other_field1, :other_field2]

In case you need to update an attribute that is never editable, i've introduced a new block syntax :

- best_in_place object do |bip|
   = bip.input field, :update_with => [:other_field1, :other_field2]
   = bip.input other_field1
   = bip.no_edit other_field2

Thanks, I'd like to have opinions before submitting a pull request

@albertbellonch
Copy link
Collaborator

Hello everyone,

We think that the best option for now is to use AJAX callbacks in order to update what you want to be updated in the view. It might not be the best possible solution but, for now, is the most practical approach.

We do not plan to implement this whole feature, but feel free to provide a pull request with tests and the implementation of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants