Note that there are some explanatory texts on larger screens.

plurals
  1. POMagicSuggest: redirect after choosing item
    primarykey
    data
    text
    <p>I am using MagicSuggest (<a href="http://nicolasbize.github.io/magicsuggest/" rel="nofollow">http://nicolasbize.github.io/magicsuggest/</a>) with CakePHP in a Helper as a contact search. My MagicSuggestHelper class looks like the following:</p> <pre><code>class MagicSuggestHelper extends AppHelper { var $name = 'MagicSuggest'; var $helpers = array('Html'); public function suggest(array $options=null){ ?&gt; &lt;div id='ms1'&gt;&lt;/div&gt; &lt;script&gt; var ms = $('#ms1').magicSuggest({ width: 300, highlight: true, allowFreeEntries: false, hideTrigger: true, expandOnFocus: true, useTabKey: true, maxSelection: 1, typeDelay: 0, name: "searchId", data: [ &lt;?php foreach($options['data'] as $suggestions){ echo"{\n"; echo"id: ".$suggestions['id'].",\n"; echo"name: \"".$suggestions['name']."\",\n"; echo"desc: \"".$suggestions['desc']."\",\n"; echo"image: \"".$suggestions['image']."\",\n"; echo"},"; } ?&gt; ], renderer: function(v){ return '&lt;div&gt;' + '&lt;div style="float:left;"&gt;&lt;img src="' + v.image + '"/ style=\"max-width:80px;max-height:80px\""&gt;&lt;/div&gt;' + '&lt;div style="padding-left: 100px;"&gt;' + '&lt;div style="padding-top: 10px;font-style:bold;font-size:100%;color:#333"&gt;' + v.name + '&lt;/div&gt;' + '&lt;div style="color: #999"&gt;' + v.desc + '&lt;/div&gt;' + '&lt;/div&gt;' + '&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;'; } }); &lt;/script&gt; &lt;?php } </code></pre> <p>This works fine for me. But when selecting an item I want to get redirected directly to the profile I just clicked on. I tried it with an onclick()-event in the first of the result which unfortunately didn't fired correctly when I used the CakePHP-HTML-Helper combined with $suggestions['id'].</p> <p>On the MagicSuggest website I found an event that is fired when changing the selection The following code can be found in the FAQ:</p> <pre><code>$(ms).on('selectionchange', function(event, combo, selection){ alert(selection); }); </code></pre> <p>I think I can use a redirect-Function here instead of the alert. But how to get the id here? Even alert(selection) returns me an alert with "object Object" which I think should not be the case.</p> <p>So how can I get the id here and redirect to my Contact view? (/contacts/view/$id). I didn't worked alot with JavaScript in the past so please also excuse beginner's mistakes.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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