AJax.InPlaceEditor - Controlling initial text selection

I want to use in-place editing, but do not want any text to be selected
when the user invokes the in-place editor. I would like the cursor to
be placed at the end of the text when the in-place editor appears
instead of having all of the text automatically selected. Is this
possible?

Thanks,
Annette

I discovered that adding the following to application.js works:

////////////////////////////////////////////////////////////////////////////////
// Manipulates the caret position in a ‘textarea’.
// It creates a selection if selStart and selEnd are not equal.
//
// To place the caret at the beginning of text:
// “setSelRange(element, 0, 0);”
////////////////////////////////////////////////////////////////////////////////
function setSelRange(inputEl, selStart, selEnd)
{
if (inputEl.setSelectionRange)
{
inputEl.setSelectionRange(selStart, selEnd);
}
else if (inputEl.createTextRange)
{
var range = inputEl.createTextRange();
range.collapse(true);
range.moveEnd(‘character’, selEnd);
range.moveStart(‘character’, selStart);
range.select();
}

inputEl.focus();
}

////////////////////////////////////////////////////////////////////////////////
// Extend Ajax.InPlaceEditor so that it does not automatically select
all
// text when the im-place editor is invoked.
////////////////////////////////////////////////////////////////////////////////
Object.extend(Ajax.InPlaceEditor.prototype, {
onLoadedExternalText: function(transport) {
Element.removeClassName(this.form,
this.options.loadingClassName);
this.editField.disabled = false;
this.editField.value = transport.responseText;

    setSelRange(this.editField, this.editField.value.length, 

this.editField.value.length);
}
});

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