In Place Editing
Posted on March 23, 2008 at 09:00 PM
I like the in_place_edit plugin.
I needed it to work with validations in my model, though. It doesn't.
I also needed it to work with a select box. It doesn't.
So after some googling I found a few extensions that accommodate each of these shortcomings....
First I found this for the validations: http://www.pluitsolutions.com/2007/03/20/custom-inplaceedit-with-validation/
This one is about a year old, and was written for Rails 1.x. Be sure you use :script => true in the calls in your view.
Then a few days ago I found this for selection: http://thetacom.info/2008/03/21/rails-in-place-editing-plugin-w-selection/#comment-7
So far I have them all working in a handful of forms. Some of them are even inside a redbox (lightbox). There is a catch, though. I was not able to get the selection edit to work with the validations. That's OK for me, though, as there are no validations required for the data in the select.
Here's what the controller looks like for that view:
Employee.content_columns.each do |column|
in_place_edit_with_validation_for :employee, column.name
end
# the select box extension doesn't seem to work with the custom in place editor
in_place_edit_for :employee, "department"
So after all of that, I stumbled across this plugin that appears to do it all: http://os.flvorful.com/super_in_place_controls
Dang. I have something that works today, but it feels a little duct taped together. I'll come back to this one.
The other thing I need to get my head around is how to put the contents of an array defined in the model into the select:
EMPLOYEE_DEPARTMENTS = [
# Displayed # stored in DB
[ "Contractor", 28 ],
[ "Account - Internal", 29 ],
[ "Account - External", 30 ],
[ "Technology", 31 ]
]
For now to get the code running I have the values duplicated in the view. That is bad, but I was focused on other things before DRYing that up. I'll get there....
Comments
There are 3 comments on this post. Post yours →
I'm currently working on another patch to the inplaceediting plugin to allow validation. I plan for it to only validate the text inputs, unless someone can show me a reason that selectbox input would need validation.
I haven't checked out the SuperInPlaceEdit yet, but I like the idea of pretty much any form element that can contain data can be edited in place. I have a form in another app that has a lot of stuff on it (checkboxes, textarea, select). I would love to be able to use in-place editing for it.
Having the in-place edit plugin do validations would be nice. The way this app is currently with the mixture of in_place_edit_for and in_place_edit_with_validation_for feels kind of dirty.
As far as validations go for a selection, I wouldn't rule the need out completely. It's not as commonly needed, though. Validating ranges or inclusion of the list would be silly. There could be a custom validation written, though, that verifies combinations. Come to think of it I don't really know how you would do that functionality in an in-place editing situation. A change in the selection would require a change in something else.
I played with SuperInPlaceEdit some, and it works OK. It puts some extra br tags in the form when you are in the edit mode, though. I spent some time trying to fix it, but not a lot. I couldn't find where it was coming from in the hour or so that I spent digging around.
The project I was doing this for got canned, though, so I will pick it back up when the need arises again.
Post a comment
Required fields in bold.