Problem with autocomplete and modal...

Problem with autocomplete and modal...

Hello, I've got a big issue using Jquery Autocomplete with modal.

the following code works good if not used in modal :

  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1">
  7.     <meta name="description" content="jquery autocomplete">
  8. <meta name="keywords" content="jquery autocomplete">
  9. <meta name="author" content="muni">
  10.     <title>jquery autocomplete using ajax php mysql </title>
  11. <link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
  12.     <!-- Bootstrap -->
  13.     
  14.     <link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css" />
  15. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  16. <link rel="stylesheet" type="text/css" href="css/main.css" />
  17.     <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  18.     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  19.     <!--[if lt IE 9]>
  20.       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  21.       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  22.     <![endif]-->
  23.     
  24. <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  25. <script type="text/javascript" src="js/jquery-ui.min.js"></script>
  26.     <script type="text/javascript" src="js/jquery-ui.js"></script>
  27. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  28.     
  29.     
  30.     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">


  31.   </head>
  32.   <body>


  33. <div class="container-fluid">
  34. <div class="row main-content">      
  35.     <div class="col-xs-12 col-sm-10 col-md-10 col-lg-10 col-sm-offset-2 col-md-offset-2 col-lg-offset-2">
  36.    
  37.         <div style="width:100%; margin-bottom: 50px;" class="text-center" >
  38.         <div style="position:relative; float:right;">
  39. <a href="javascript:void(null);" onclick="showDialog();" title="Article"><button type="button" id="dialog-link"
  40.     class="btn btn-primary">Choisir client</button></a>
  41. </div>

  42. </div>
  43. </div>
  44.             
  45.             <!-- ***************************************************************** -->
  46. <!-- ui-dialog1 Choisir client -->
  47. <!-- ***************************************************************** -->
  48. <div id="client-modal" title="Fiche client" style="display: true;">
  49. <div class="col-sm-12 col-md-12">
  50. <form id="horsBon1" name="horsBon1" action="mods/bc/mod_bc_client.php?id_bc=" method="post"
  51.         target="_parent" name="monform" autocomplete="off">

  52. <div class="row">
  53. <div class="col-sm-3 col-md-3">
  54. <div class="input-group">
  55. <span class="input-group-addon">CP</span>
  56. <input type="text" name="cp_" id="cp" class="form-control maj" value=""
  57.                             placeholder="Code Postal" onfocus="this.select();" onkeypress="if (event.keyCode==13){ this.form.ville.focus();}">

  58. </div>  
  59. </div>

  60. <div class="col-sm-5 col-md-5">
  61. <div class="input-group">
  62. <span class="input-group-addon">Ville</span>
  63. <input size="16" class="form-control maj" type="text" name="ville_" id="ville" value=""
  64.                             placeholder="Ville" onfocus="this.select();" onkeypress="if (event.keyCode==13){ this.form.pays.focus();}">
  65. </div>
  66. </div>
  67. </div>
  68.                 <div class="formSep"> </div>

  69. <div class="row" align="right" style="padding-right:10px;">
  70.     <button onClick="window.parent.jQuery('#client-modal').dialog('close');" type="button" class="btn btn-default">Annuler</button>
  71.     <button id="submit1" onClick="javascript:document.horsBon1.submit();" type="button" class="btn btn-default">Confirmer</button>
  72. </div>                
  73. </form>
  74. </div>
  75. </div>
  76. <!-- ***************************************************************** -->
  77. <!-- Fin ui-dialog Choisir client -->
  78. <!-- ***************************************************************** -->
  79. </div>
  80. </div><!-- /container -->
  81. <div class="clearfix"></div>
  82.     
  83.     <!-- Footer -->
  84.     <footer>

  85.     </footer>
  86.     <!-- /Footer -->
  87.     
  88.     
  89.     
  90.     <script type="text/javascript">


  91. </script>
  92.     <script src="js/auto.js"></script>
  93.   </body>
  94. </html>
and the javascript : 

  1. function showDialog()
  2. {
  3. $("#client-modal").dialog({
  4. width: 850,
  5. height: 400,
  6. modal: true,
  7. })
  8. };


  9. $('#cp').autocomplete({
  10. source: function( request, response ) {
  11. $.ajax({
  12. url : 'ajax.php',
  13. dataType: "json",
  14. method: 'post',
  15. data: {
  16.   name_startsWith: request.term,
  17.   type: 'country_table',
  18.   row_num : 1
  19. },
  20. success: function( data ) {
  21. response( $.map( data, function( item ) {
  22. var code = item.split("|");
  23. return {
  24. label: code[0] + " - " + code[1],
  25. value: code[0],
  26. data : item
  27. }
  28. }));
  29. }
  30. });
  31. },
  32. autoFocus: true,      
  33. minLength: 0,
  34. select: function( event, ui ) {
  35. var names = ui.item.data.split("|");
  36. $('#cp').val(names[0]);
  37. $('#ville').val(names[1]);
  38. }      
  39. });
so the script works good when used out of the modal, but when I use it with the modal, nothing happen ;/

Can some one help me please?


Thank you very much.