Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Nerea on Jan 09, 2009 01:19
open dhtmlx forum
Set focus to an input

How can I set focusa to a input in a toolbar?

I have a toolbar with an input a grid.
When I open a window clicking on a row and close it later iI can't click into the input. It seems as the toolbar has losed the focus.
Answer posted by Support on Jan 09, 2009 01:26
It seems your toolbar covered by windows' viewport.
Could you please provide us a source code?
Answer posted by Nerea on Jan 09, 2009 01:56

Here is my code.

The toolbar is loaded from an xml file.

<body bgcolor="#dfefff">

<script>

 window.dhx_globalImgPath="img/"; 
 dhxWins = new dhtmlXWindows(); 
 
 
 //Patch for taborder in grid
 dhtmlXGridObject.prototype._init_point_key_patch=dhtmlXGridObject.prototype._init_point;
 dhtmlXGridObject.prototype._init_point = function(){
 this._nextRow=function(ind, dir){
  var r = this.render_row(ind+dir);
  if (!r || r==-1) return null;
  if (r&&r.style.display == "none")
   return this._nextRow(ind+dir, dir);

  return r;
 }
 this._init_point=this._init_point_key_patch;
 if (this._init_point) this._init_point();
 }
 
 
 function crearVentana(tipo, rowId){
  if (mygrid.getSelectedRowId() != null || (tipo == '0')){   
   
   if(!dhxWins.window("w1")){ //   
    dhxWins.enableAutoViewport(false);
    dhxWins.setViewport(70, 15, 512, 445);
    dhxWins.vp.style.border = "#909090 0px solid"; 
    dhxWins.attachEvent("onContentLoaded", function(win) {  //focus en el primer text_box enabled
     win.progressOff();
     if (_isIE && win.getId() == "w1") {          
      win._frame.contentWindow.document.getElementById("txt_Nombre").focus();
     }
    });     
    
    w1 = dhxWins.createWindow("w1",0, 0, 512, 445); 
    w1.progressOn();
    // hiding button max, min y contraer
       w1.button("minmax1").hide();
       w1.button("minmax2").hide();
       w1.button("park").hide();  
       //No permite
       w1.denyResize(); // deny resizing
       w1.denyMove();   // deny moving    
       w1.setModal(true);
    w1.attachURL("forpagdata.php?tipo="+tipo+"&cod="+rowId);     
   }      
  }  
  
 } 
       
 function recargar(){
  mygrid.clearAll(false);

 }

</script>
<div id="toolbarMenu" style="width:689px;overflow:hidden;"></div>
<script>
 
 var webBar = new dhtmlXToolbarObject("toolbarMenu");
 webBar.setIconsPath("../img/");
 webBar.loadXML("../xml/webBar.xml?etc="+new Date().getTime(),function(){
  // disable botones
     disableBar();
 });
 

 webBar.attachEvent("onClick", function(id){  
  
  switch(id){
  case "new":      
   crearVentana('0', "");   
   break;
  case "open":   
   crearVentana('1', mygrid.getSelectedRowId());   
   break;
  case "copy":   
   crearVentana('2', mygrid.getSelectedRowId());
   break;
  case "delete":
   crearVentana('3', mygrid.getSelectedRowId());
   break;
  case "print":   
   break;  
  case "pdf":
   window.open('pdfforpag.php');
   break;
  case "find":
   //cargar fichero con filtro
   mygrid.clearAndLoad("gridForPag.php?etc=" + new Date().getTime() + "&filtro=" + webBar.getValue('filter_text'));
   break;
  }
 
  });
  
     
  function enableBar(){
   webBar.enableItem("open");
   webBar.enableItem("copy");
   webBar.enableItem("delete");
  }
  
  function disableBar(){
   webBar.disableItem("open");
   webBar.disableItem("copy");
   webBar.disableItem("delete");
  }

  
</script>


<div id="gridbox" style="height:443px;width:689px;background-color:white;overflow:hidden;"></div>

<script>
 var last_Id =''; //Id seleccionado
 var mygrid = new dhtmlXGridObject("gridbox");
 mygrid.setEditable(true);
 mygrid.setSkin("light");
 //enable tooltips for last column
     mygrid.enableTooltips("false,true,true");
     //moverse entre las filas con el teclado
 mygrid.enableKeyboardSupport(true);  
 //seleccionar fila
 mygrid.attachEvent("onRowSelect",doOnRowSelect); 
 mygrid.attachEvent("onRowDblClicked",doOnRowDblClicked);
 mygrid.attachEvent("onEnter",doOnEnter);   
 //mygrid.setExternalTabOrder("bBuscar","bCalendario");
 //tabulacion
 mygrid.enableEditTabOnly(1);
 //solo se pude seleccionar uno 
 mygrid.enableMultiselect(false);     
     //Carga cada 50 registros   
     mygrid.enableSmartRendering(true,50);     
     //cargar fichero 
   mygrid.loadXML("gridForPag.php");

 function doOnRowSelect(rowId){
   textoNegrita(rowId);     
   enableBar();
      }

 function doOnRowDblClicked(rowId){
   textoNegrita(rowId);      
   crearVentana('1',rowId);//Abrir cliente 
   enableBar();  
      }

 function doOnEnter(rowId){    
   textoNegrita(rowId);   
   crearVentana('1',rowId);//Abrir cliente
   enableBar();
         }

 function textoNegrita(rowId){  //Ponemos en negrita el texto seleccionado y en normal el anterior  
  if (last_Id != ''){
   mygrid.setRowTextNormal(last_Id);
  }
         mygrid.setRowTextBold(rowId);
  last_Id = rowId;
 }

 </script>
 </body>