jquery ui 1.7 autocomplete show dialog on select

Posted by Daniel S on Stack Overflow See other posts from Stack Overflow or by Daniel S
Published on 2010-03-30T16:40:12Z Indexed on 2010/03/30 16:43 UTC
Read the original article Hit count: 436

Filed under:
|
|
|

Hello, I am using an autocomplete widget, and would like a dialog to show when an item is selected. The dialog does show up, but I want a field in the dialog to receive focus when it opens. Here is what I have tried so far:

//HTML

<form action="#">
  <p><input id="busca" /></p>
</form>
<div id="agregar" title="Agregar Parte">
  <label for="cantidad">Cantidad:</label>
  <input name="cantidad" id="cantidad" size="3" />
</div>

//jquery

 $(function(){

        $("#agregar").dialog({
                        autoOpen: false,
                        //also tried open: function(){$("#cantidad").focus()}
                        }
              );      
        //.bind("dialogfocus", ... ) does not work either
        $("#agregar").bind("focus", function(){
                   $("#cantidad").focus(); });

    $("#busca").autocomplete({
            source: "/carrito/autocomplete/",
            minLength: 1,
                        select: function(e, ui) {
                          $("#agregar").dialog("open");
                        }
        });


      });

I think autoselect's default behavior is still doing something as the autoselect widget receives focus after the dialog is shown.

Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui