0
$("#destination1" + countVar).autocomplete({

        minLength : 3,
        source : function(request, response) {
            var url = configOptions.icaocodeUrl;
            var term = request.term;
            url=url+term;
            console.log(url);
            $.ajax({
                url : url,
                type : "GET",
                data : request,
                dataType : "json",
                success : function(data) {
                    response(data.slice(0, 10));
                    //alert(data);
                },error: function(xhr, textStatus) {
                    alert('error'); 
                }
            });
        },
        change:function(event,ui){
            console.log("fired in dest2");
        },close:function(event,ui){
            console.log("close in dest2"+'#dof1'+countVar);
            console.log(countVar);
            $(this).parents('form').find('#dof1'+countVar)
              .filter(function () { return $(this).val() === ''; })
              .first().focus();             

            }
    });

above is my code for autocomplete and autotab(autofocus) to next field for dynamically created elements.autotab(autofocus ) is working fine for normal html but it is not working for dynamically created elements only.

1 Answers1

0

Are you trying to focus() on a tab that is being dynamically added? If so, you might be triggering focus() to soon and the DOM element might not be there.

Try wrapping the focus function into a setTimeout() function to test it out.

setTimeout(function () {
    $(this).parents('form').find('#dof1'+countVar)
          .filter(function () { return $(this).val() === ''; })
          .first().focus();   
}, 2000); // 2 seconds
ThiagoPXP
  • 5,362
  • 3
  • 31
  • 44