I have a placeholder ‘pre-text’ value which is given to a comment form
input via the application.js;
Event.observe(window, ‘load’,
comment_pre_text = “Leave a comment…”
var el = $(‘comment_body’)
if(el) {
el.value = comment_pre_text
Event.observe(el, ‘focus’, function() { if(this.value ==
comment_pre_text) this.value = ‘’; })
Event.observe(el, ‘blur’, function() { if(this.value == ‘’) this.value =
comment_pre_text; })
}
}
);
However, I’ve since started using RJS to make submissions through the
comment form, and now the pre-text js breaks - it doesn’t show the
pre-text after a form submission unless I click in and then out of the
comment form. This problem could be fixed by turning the comments in the
following RJS template in to working code (which I haven’t worked out
how to do yet);
page.insert_html :bottom, :items_wrapper, :partial => “comment”, :object
=> @comment
page[:comment_form].reset
focus on the comment input
focus out of the comment input
page.visual_effect :highlight, “comment_#{@comment.id}”
flash.discard
Alternatively, I expect this problem could also be fixed by adding
another line to the application.js, which I imagine would read something
like this (I’m new to js and I can’t find a ‘reset’ equivalent to
‘focus’ or ‘blur’ yet - both of which I don’t understand fully);
Event.observe(el, ‘reset’, function() { if(this.value == ‘’) this.value
= comment_pre_text; })
}
Any ideas?