Annette Crowley
2008-Sep-02 01:14 UTC
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Annette Crowley
2008-Sep-02 02:31 UTC
Re: AJax.InPlaceEditor - Controlling initial text selection
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); } }); -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---