Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlight on a autocomplete with XML
    primarykey
    data
    text
    <p>I am creating a search with autocomplete based on a XML file. I would like when the user enter a word, the text will be hightligh.</p> <p>What I have done so far :</p> <pre><code>$(function() { function log( message ) { $( "&lt;div/&gt;" ).text( message ).prependTo( "#log" ); $( "#log" ).scrollTop( 0 ); } $.ajax({ url: "ecole.xml", dataType: "xml", success: function( xmlResponse ) { var data = $( "school", xmlResponse ).map(function() { return { value: $( "name", this ).text() + ", " + ( $.trim( $( "adress", this ).text() ) + ", " + $( "description", this ).text() || "(unknown article)" ), id: $( "id", this ).text(), text: $( "description", this ).text() }; }).get(); $( "#birds" ).autocomplete({ source: data, minLength: 0, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.value + ", Id: " + ui.item.id + ", Text: " + ui.item.text : "Nothing selected, input was " + this.value ); }, }); } }); }); </code></pre> <p>I don't really understand how to do to highlight the text. I use this code :</p> <pre><code>$(function() { highlight: function(match, keywords) { keywords = keywords.split(' ').join('|'); return match.replace(new RegExp("("+keywords+")", "gi"),'&lt;b&gt;$1&lt;/b&gt;'); } }); </code></pre> <p>But I don't really now why and it doesn't work</p> <p>Here's my HTML / PHP :</p> <pre><code> &lt;div id="RecentEdition"&gt; &lt;?php $schools = simplexml_load_file('ecoles.xml'); foreach ($schools-&gt;RecentEdition as $RecentEdition): foreach ($RecentEdition-&gt;school as $school): ?&gt; &lt;figure&gt; &lt;img src='&lt;?php echo "{$school-&gt;image} \n"; ?&gt;' title='' /&gt; &lt;figcaption&gt; &lt;h3&gt;Contents&lt;/h3&gt; &lt;p class="over"&gt; &lt;ul&gt; &lt;?php foreach ($school-&gt;content as $content): ?&gt; &lt;?php foreach ($content-&gt;chap as $chap): ?&gt; &lt;li&gt;&lt;a href="&lt;?php echo "{$chap['link']} \n"; ?&gt;"&gt;&lt;?php echo "{$chap} \n"; ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;/p&gt; &lt;p class="go"&gt; &lt;a href="&lt;?php echo "{$school-&gt;link} \n"; ?&gt;"&gt;View »&lt;/a&gt; &lt;/p&gt; &lt;/figcaption&gt; &lt;/figure&gt; &lt;?php endforeach; ?&gt; &lt;?php endforeach; ?&gt; &lt;/div&gt; </code></pre> <p>And here's my XML:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;schools&gt; &lt;RecentEdition&gt; &lt;school&gt; &lt;name&gt;École1&lt;/name&gt; &lt;id&gt;1&lt;/id&gt; &lt;link&gt;./Marlburian0809/index.html&lt;/link&gt; &lt;image&gt;./img/zine.jpg&lt;/image&gt; &lt;content&gt; &lt;chap link="./Marlburian0708/#/2/"&gt;The Master's Speech&lt;/chap&gt; &lt;chap link="./Marlburian0809/#/8/"&gt;College Community&lt;/chap&gt; &lt;chap link="./Marlburian0809/#/50/"&gt;Trips n Expeditions&lt;/chap&gt; &lt;chap link="./Marlburian0809/#/64/"&gt;Creative Arts&lt;/chap&gt; &lt;chap link="./Marlburian0809/#/92/"&gt;Sports&lt;/chap&gt; &lt;/content&gt; &lt;description&gt; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer luctus porta turpis, id congue nisi dapibus nec. Maecenas pulvinar blandit turpis, sit amet viverra arcu convallis id. Donec varius blandit orci nec molestie. Cras auctor, metus eget volutpat hendrerit, massa nibh tempor nunc, volutpat ultrices nibh eros vestibulum nulla. Aenean libero risus, auctor sed blandit ut, tincidunt non est. Nullam bibendum nunc non tortor eleifend consectetur. Proin porttitor, diam ac varius semper, leo odio mattis erat, id luctus ligula libero eu mi. Proin et lacus ligula. Quisque non consequat mauris. Morbi dolor mi, dapibus a condimentum ac, luctus at elit. Praesent sit amet felis at magna sagittis pharetra et vitae neque. &lt;/description&gt; &lt;/school&gt; &lt;/RecentEdition&gt; &lt;/schools&gt; </code></pre> <p>And an another question. If I have a big text in my autocomplete e.g : </p> <blockquote> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate nibh urna. Aliquam in arcu vel diam malesuada malesuada. Ut volutpat hendrerit sollicitudin. Quisque vestibulum adipiscing rhoncus. Curabitur laoreet interdum tempus. Aliquam sit amet urna quis dui rhoncus venenatis iaculis id arcu. Proin sit amet tincidunt est. Aenean ut tellus lectus. Vestibulum ac enim orci.</p> </blockquote> <p>I would like that if you write the world « Interdum tempus », the result display : « …laoreet interdum tempus. Aliquam sit… » </p> <p>Is it possible ?</p> <p>Many thanks for you help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload