I have a show page with an in place editor field for description. It
works great when description is populated. description can be nil, so I
notice that when I show a record with no description, the in place
editor either doesn’t work or has no place to click to edit. This is
still something i’d like to have work. Is there something additional I
have to do for when description isn’t populated?
use the :external_control option on the in_place_editor_field
its the easiest way.
Thanks for this option. I was unable to find it in the api, so I tried: Description:
<%= in_place_editor_field :goal, :description, :external_control %>
But that didn’t work. Then I fooled around a bit until I got to:
And that compiled but still didn’t work. Any further sugestions besides
setting the default value in the DB to “Add a description here” as the
other poster suggests?
Any further sugestions besides setting the default value in the DB to
“Add a description here” as the other poster suggests?
I sure wish someone could answer this question. I have been poking
around
and don’t see anything that explains the syntax of the
in_place_editor_options well enough that I can make this work. One thing
that I wasted a bunch of time on was the :click_to_edit_text - that
isn’t
what Mike and I want. Instead it is supposed to change the tooltip text
when
you mouse over the text to edit.
Is there a way for me to create a non-database backed attribute for the
fake
text? and then still have the real attribute edited? It doesn’t look
like
that is easy to do the way the In Place Editor API is set up.
I ran into this problem as well with in_place_editor. The :empty_text
parameter hack is good. What I wound up doing is using an
:external_control which is small-font “edit” text right next to whatever
someone might want to edit. If the data is nil the “edit” link is still
there. I find this looks better anyway, since short-length values are
not that easy to click on.
Here’s my code:
<% if logged_in? && admin? %>
<%=edit_text(@style,‘style_num’)%>
<% end %>
<%= in_place_editor_field(‘style’,‘style_num’,{},{:external_control =>
edit_id(@style,‘style_num’), :size => 10})%>
and as helpers:
def edit_id(object,field)
“edit_#{object.class.to_s.downcase}#{object.id}#{field}”
end
def edit_text(object,field)
“<span class="edit" id="#{edit_id(object,field)}">edit”
end
Also, a warning: in_place_editor is broken for non-string values! If you
try to change an integer type to nil (remove it, basically) you get a
nasty error. I submitted a very easy patch for this:
I dropped it in, restarted my server, and then started using it. For
other newbies, that involved changing the controller line to add the
:empty_text parameter:
in_place_edit_for :page, :comments, :empty_text => ‘(add comment)’
And changing my invocation of in_place_editor_field to include the
in_place_editor_options hash:
<%= in_place_editor_field :page, :comments, {}, {
:nil_content_replacement => ‘(add comment)’ } %>