Passing Ajax.InPlaceEditor options

I’ve followed the instructions in the Rails Recipe #1 and have the
in_place_editor_field working but now I want to tweak how it looks and
behaves. I’d like to be able to override the default yellow highlight
color,
which is done using the highlightcolor param according to the
scriptaculous
documentation (unless I’m missing something).

I’m new to Ruby and Rails so I’m hoping that I’m just missing something.

My view code looks like this:

<%= in_place_editor_field :platform, :name %>

I’ve tried various forms of these options:

<%= in_place_editor_field :platform, :name, {}, { :highlightcolor =>
#EAEAEA” } %>
<%= in_place_editor_field :platform, :name, {}, { “highlightcolor” =>
#EAEAEA” } %>
<%= in_place_editor_field :platform, :name, {}, :in_place_editor_options
=>
{ :highlightcolor => “#EAEAEA” } %>

None of those worked, no error and no difference in the Ruby generated
javascript code.

Thanks in advance.

Kyle H.
www.kyleheon.com

Kyle H. wrote:
I’ve followed the instructions in the Rails Recipe #1 and have the
in_place_editor_field working but now I want to tweak how it looks and
behaves.

I’m going from memory here, but I don’t believe there are options baked
into the in_place_editor methods that allow you to customize it to that
degree.

However, in that same book (Rails Recipes) there’s another recipe that
goes into the JavaScript files where the inline editor is defined. The
purpose of that recipe is to create a custom in_place_editor field for
select lists. I’m sure while following along in that chapter you will
find what you’re looking for.

  • Daniel

Kyle H. wrote:

<%= in_place_editor_field :platform, :name %>

I’ve tried various forms of these options:

<%= in_place_editor_field :platform, :name, {}, { :highlightcolor =>
#EAEAEA” } %>
<%= in_place_editor_field :platform, :name, {}, { “highlightcolor” =>
#EAEAEA” } %>
<%= in_place_editor_field :platform, :name, {}, :in_place_editor_options
=> { :highlightcolor => “#EAEAEA” } %>

Hi,

As another person noted; these aren’t supported by Rails yet. I actually
did a quickie and just created my own in_place_editor_field_ext in my
application_helper. This is the full code adding support for all the
interesting InPlaceEditor-helpers. Hmm. Maybe I should submit this code
to the core?

def in_place_editor_ext(field_id, options = { })
function = “new Ajax.InPlaceEditor(”
function << "’#{field_id}’, "
function << “’#{url_for(options[:url])}’”

js_options = {}
js_options[‘okButton’] = options[:ok_button] if options[:ok_button]
js_options[‘cancelLink’] = options[:cancel_link] if
options[:cancel_link]
js_options[‘savingText’] = %(’#{options[:saving_text]}’) if
options[:saving_text]
js_options[‘clickToEditText’] = %(’#{options[:click_to_edit_text]}’)
if options[:click_to_edit_text]
js_options[‘highlightcolor’] = %(’#{options[:highlight_color]}’) if
options[:highlight_color]
js_options[‘highlightendcolor’] =
%(’#{options[:highlight_end_color]}’) if options[:highlight_end_color]

js_options[‘cancelText’] = %(’#{options[:cancel_text]}’) if
options[:cancel_text]
js_options[‘okText’] = %(’#{options[:save_text]}’) if
options[:save_text]
js_options[‘loadingText’] = %(’#{options[:loading_text]}’) if
options[:loading_text]
js_options[‘rows’] = options[:rows] if options[:rows]
js_options[‘cols’] = options[:cols] if options[:cols]
js_options[‘size’] = options[:size] if options[:size]
js_options[‘externalControl’] = “’#{options[:external_control]}’” if
options[:external_control]
js_options[‘loadTextURL’] = “’#{url_for(options[:load_text_url])}’”
if options[:load_text_url]
js_options[‘ajaxOptions’] = options[:options] if options[:options]
js_options[‘evalScripts’] = options[:script] if options[:script]
js_options[‘callback’] = “function(form) { return #{options[:with]}
}” if options[:with]
function << (’, ’ + options_for_javascript(js_options)) unless
js_options.empty?

function << ‘)’

javascript_tag(function)
end

def in_place_editor_field_ext(object, method, tag_options = {},
in_place_editor_options = {})
tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
tag_options = {:tag => “span”, :id =>
“#{object}#{method}#{tag.object.id}in_place_editor", :class =>
“in_place_editor_field”}.merge!(tag_options)
in_place_editor_options[:url] = in_place_editor_options[:url] ||
url_for({ :action => "set
#{object}_#{method}”, :id => tag.object.id })
tag.to_content_tag(tag_options.delete(:tag), tag_options) +
in_place_editor_ext(tag_options[:id], in_place_editor_options)
end


Ola B. (http://ola-bini.blogspot.com)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs