From: Moritz Bunkus Date: Wed, 18 Nov 2020 10:22:25 +0000 (+0100) Subject: ClientJS: Funktion zum Setzen der Cursorposition (z.B. in textareas) X-Git-Tag: kivitendo-mebil_0.1-0~9^2~635 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a2179ea178c2e8cdcef9fd0cab517048778383de;p=kivitendo-erp.git ClientJS: Funktion zum Setzen der Cursorposition (z.B. in textareas) --- diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 336f97144..7d8c362c9 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -123,6 +123,8 @@ my %supported_methods = ( run_once_for => 3, # kivi.run_once_for(, ) scroll_into_view => 1, # $()[0].scrollIntoView() + + set_cursor_position => 2, # kivi.set_cursor_position(, ) ); my %trim_target_for = map { ($_ => 1) } qw(insertAfter insertBefore appendTo prependTo); diff --git a/js/client_js.js b/js/client_js.js index 9fc14b6c6..d231d10ca 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -113,7 +113,7 @@ ns.eval_json_result = function(data) { // ## jQuery UI dialog plugin ## - // Opening and closing and closing a popup + // Opening and closing a popup else if (action[0] == 'dialog:open') kivi.popup_dialog(action[1]); else if (action[0] == 'dialog:close') $(action[1]).dialog('close'); @@ -159,6 +159,7 @@ ns.eval_json_result = function(data) { else if (action[0] == 'run') kivi.run(action[1], action.slice(2, action.length)); else if (action[0] == 'run_once_for') kivi.run_once_for(action[1], action[2], action[3]); else if (action[0] == 'scroll_into_view') $(action[1])[0].scrollIntoView(); + else if (action[0] == 'set_cursor_position') kivi.set_cursor_position(action[1], action[2]); else console.log('Unknown action: ' + action[0]); diff --git a/js/kivi.js b/js/kivi.js index b2b39e180..77dfe5c63 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -662,6 +662,15 @@ namespace("kivi", function(ns) { $input.parent().replaceWith($area); $area.focus(); }; + + ns.set_cursor_position = function(selector, position) { + var $input = $(selector); + if (position === 'end') + position = $input.val().length; + + $input.prop('selectionStart', position); + $input.prop('selectionEnd', position); + }; }); kivi = namespace('kivi');