This topic is locked
[SOLVED]

 ajax autocomplete in popup

11/6/2011 9:29:22 AM
PHPRunner General questions
M
mickna author

I wonder, if anyone has tried to build an jQuery autocomplete in add/edit page in popup mode?
I can add this function to add/edit page as a separate page.

If I switch the page to pop up, I can't even find the <ul class="..."> tag with the auto populated values from the array...
thx,

mickna

M
mickna author 11/7/2011

Ok, one step further and now lost in space.

I can call the auto complete in my add/edit page if it is not set as "pop up".

However, if I set add/edit as a pop up, jquery seams not to send the code.
In normal view, I can see via firebug following code at the end of the page:

<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 175px; left: 763px; display: none;">

<li class="ui-menu-item" role="menuitem">

<a class="ui-corner-all" tabindex="-1">BASIC</a>

</li>

<li class="ui-menu-item" role="menuitem">

<a class="ui-corner-all" tabindex="-1">COBOL</a>

</li>

<li class="ui-menu-item" role="menuitem">

<a class="ui-corner-all" tabindex="-1">Ruby</a>

</li>

</ul>


Put with pop up I miss these lines. I have no idea, what I have to change.

Any help?
My code:
Add page / two php snippet:



echo '

<script src="include/jquery.js"></script>

<script src="include/jquery.ui.core.js"></script>

<script src="include/jquery.ui.widget.js"></script>

<script src="include/jquery.ui.position.js"></script>

<script src="include/jquery.ui.autocomplete.js"></script>

<LINK rel=stylesheet type=text/css href="styles/jquery.ui.autocomplete.css">

<meta charset="utf-8">

<script>

$(function() {

var availableTags = [ //Just for testing propose

"ActionScript",

"AppleScript",

"Asp",

"BASIC",

"C",

"C++",

"Clojure",

"COBOL",

"ColdFusion",

"Erlang",

"Fortran",

"Groovy",

"Haskell",

"Java",

"JavaScript",

"Lisp",

"Perl",

"PHP",

"Python",

"Ruby",

"Scala",

"Scheme"

];

function split( val ) {

return val.split( /,\s*/ );

}

function extractLast( term ) {

return split( term ).pop();

}
$( "#tags" ).bind( "keydown", function( event ) {

if ( event.keyCode === $.ui.keyCode.TAB &&

$( this ).data( "autocomplete" ).menu.active ) {

event.preventDefault();

}

})

.autocomplete({

minLength: 0,

source: function( request, response ) {

// delegate back to autocomplete, but extract the last term

response( $.ui.autocomplete.filter(

availableTags, extractLast( request.term ) ) );

},

focus: function() {

// prevent value inserted on focus

return false;

},

select: function( event, ui ) {

var terms = split( this.value );

// remove the current input

terms.pop();

// add the selected item

terms.push( ui.item.value );

// add placeholder to get the comma-and-space at the end

terms.push( "" );

this.value = terms.join( ", " );

return false;

}

});
$(".ui-autocomplete").position({

my: "left top",

at: "left bottom",

of: $("#tags"),

collision: "flip flip"

});
});

</script>

';




echo '<div class="demo">

<div class="ui-widget">

<label for="tags">Tag programming languages: </label>

<input aria-haspopup="true" aria-autocomplete="list" role="textbox" autocomplete="off" class="ui-autocomplete-input" id="tags" size="50">

</div>

</div>';
C
cgphp 11/7/2011

Don't use PHP snippet to include js files. Check this article: http://xlinesoft.com/phprunner/docs/how_to_add_external_files.htm

M
mickna author 11/7/2011

Thank you Christian for this hint.
However, it does not change anything in the behaviour. Still not working.

Any ideas?

C
cgphp 11/7/2011

It's hard to say what's not working without seeing your actual files.
In the visual editor switch to HTML and follow these steps:

  1. Add the following code after the <END body> tag:

<script src="include/jquery.ui.core.js"></script>

<script src="include/jquery.ui.widget.js"></script>

<script src="include/jquery.ui.position.js"></script>

<script src="include/jquery.ui.autocomplete.js"></script>


2. Add your style after the following line:

<link REL="stylesheet" href="include/style.css" type="text/css">


3. Add the JS code (without script tag) in the "javascript onload" event:

var availableTags = [ //Just for testing propose

"ActionScript",

"AppleScript",

"Asp",

"BASIC",

"C",

"C++",

"Clojure",

"COBOL",

"ColdFusion",

"Erlang",

"Fortran",

"Groovy",

"Haskell",

"Java",

"Javascript",

"Lisp",

"Perl",

"PHP",

"Python",

"Ruby",

"Scala",

"Scheme"

];

function split( val ) {

return val.split( /,\s*/ );

}

function extractLast( term ) {

return split( term ).pop();

}
$( "#tags" ).bind( "keydown", function( event ) {

if ( event.keyCode === $.ui.keyCode.TAB &&

$( this ).data( "autocomplete" ).menu.active ) {

event.preventDefault();

}

})

.autocomplete({

minLength: 0,

source: function( request, response ) {

// delegate back to autocomplete, but extract the last term

response( $.ui.autocomplete.filter(

availableTags, extractLast( request.term ) ) );

},

focus: function() {

// prevent value inserted on focus

return false;

},

select: function( event, ui ) {

var terms = split( this.value );

// remove the current input

terms.pop();

// add the selected item

terms.push( ui.item.value );

// add placeholder to get the comma-and-space at the end

terms.push( "" );

this.value = terms.join( ", " );

return false;

}

});
$(".ui-autocomplete").position({

my: "left top",

at: "left bottom",

of: $("#tags"),

collision: "flip flip"

});
M
mickna author 11/7/2011

Hi Christian,
I am sorry, not the solution.

If I input my code in "javascript onload" I'll get an Error (function not found)
As I wrote, all work fine if I do not use pop up for add/edit.

I believe this is an issue with ibox and Jquery auto complete. May it is loosing focus, or... (well, I have no clue)
But again thanks!

mickna