Auto-select text for all editor instances
Auto-select text for all editor instances
I've got an app with tens of Editor instances across several pages, using both inline and main editors.
I want to auto-select the text in any text field when a user clicks to edit it, as described here:
https://datatables.net/forums/discussion/24740/selection-of-text-in-inline-editor
But I want to apply this across all my Editor instances. Is there a simple way (e.g. by updating the Editor code) to make this the default behavior?
My working solution is to register this listener on all pages:
$(document).on('focus', '.DTE_Field input[type="text"]', function () { this.select() })
That seems to do the trick (except I'll need a slightly different selector to include text
fields with attr: {type: 'number'}
, and maybe some other edge cases), but I'm wondering if there's a cleaner way to approach this via the Editor API or with a quick change to the Editor code?
This question has an accepted answers - jump to answer
Answers
I think you've hit upon the best option at this time. I could look into providing an
onFocus
option for theform-options
object in future though, which would basically do the same thing.Allan
This is not currently possible with DataTables Editor. You can however use the select() API method to select the text in a single instance of an Editor.
@bobford Are you referring to the
select()
method shown in the original post (which is a DOM method, not Editor specific), or some other method?Allan