jquery - Using a jqueryui dialog, I'm trying to focus on a textarea but the cursor never appears -


i'm using

  • jquery : 1.9.1
  • jqueryui : 1.10.2
  • all browsers show same behaviour -

so i'm launching jquery dialog anytime right-clicks textarea element. noticed textarea getting focus active cursor when gets right-clicked, call blur() on element rid of cursor.

works, no problem.

then in dialog, if user clicks "edit" want put cursor active on text area. call show(), , focus() [see code below], doesn't focus back. no errors, nothing happens besides dialog closing want (dialog closes, textarea should have active cursor doesn't).

below code, appreciated, i've been trying figure out few hours. identified code expect work doesn't "this problem"

html

this element jqueryui dialog. when user right-clicks target element, shows content of dialog

<div id="popupdialog">     <input type="button" id="editrowbutton" class="contextmenubutton"            value="edit"> </div>   

throughout page have these textareas when right-clicked, show jqueryui dialog.

<textarea id="targetthatwasrightclicked" >some content in textarea</textarea> 

javascript

<!-- handler used clear dialog if clicks outside dialog.--> <!-- working fine. --> $(document).bind('click',function(){     // if dialog open, close     if( $("#popupdialog").dialog("isopen" ) ) {         closedialog();     } });   function closedialog() {     mydialog.target = null;     $("#popupdialog").dialog("close" ); <!-- invokes jquery close method. -->                                          <!-- working fine --> };   <!-- used initialize jqueryui dialog, holds reference --> <!-- object gets right-clicked "target". --> var mydialog = {      target : null,      init : function() {         $('#popupdialog').dialog({             modal: true,             dialogclass: "no-close",             width:'auto',             height:'auto',             resizable: false,             autoopen: false         }); }   <!-- general setup stuff when $(document).ready(..) function called. --> function initsidemenu() {      $("#editrowbutton" ).button();      $('#editrowbutton').click( function() {          <!-- problem: expect textarea (the target) have -->         <!-- blinking cursor in after these next 2 commands,  -->         <!-- remains unselected. -->         mydialog.target.show();         mydialog.target.focus();          closedialog();     });      mydialog.init();       $("#targetthatwasrightclicked").on("contextmenu", function(e){          var target = $(e.target);          <!-- right-click focussed on textarea, un-focus -->         <!-- cursor isn't blinking in textarea. -->         target.blur();          <!-- set "target" = right-clicked element , open dialog box -->         mydialog.target = target;         $('#popupdialog').dialog('open');          e.preventdefault();  <!-- browser's contextmenu doesn't appear. -->         e.stoppropagation(); <!-- document click handler doesn't called -->                              <!-- , close dialog. -->     });  } 

try close dialog before focus:

    mydialog.target.show();     closedialog();      mydialog.target.focus(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -