UNPKG

magicsuggest

Version:

MagicSuggest is a multiple selection auto-suggest input box for Bootstrap 3.

172 lines (156 loc) 6.14 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="MagicSuggest is a multiple selection combo box built for bootstrap themes"> <meta name="author" content="Nicolas Bize"> <link rel="shortcut icon" href="http://nicolasbize.com/magicsuggest/assets/ico/favicon.ico"> <title>MagicSuggest - Tutorial</title> <link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/custom.css" rel="stylesheet"> <link href="assets/lib/highlightjs/styles/default.css" rel="stylesheet"> <script type="text/javascript" src="assets/lib/highlightjs/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="lib/bootstrap/js/bootstrap.min.js"></script> </head> <body> <a id="forkme_banner" href="https://github.com/nicolasbize/magicsuggest">View on GitHub</a> <div class="site-wrapper"> <div class="site-wrapper-inner"> <div class="cover-container"> <div class="masthead clearfix"> <div class="inner"> <h3 class="masthead-brand">MagicSuggest</h3> <ul class="nav masthead-nav"> <li><a href="index.html">Home</a></li> <li><a href="examples.html">Examples</a></li> <li><a href="doc.html">Documentation</a></li> <li class="active"><a href="tutorial.html">Tutorial</a></li> </ul> </div> </div> </div> <div class="tutorial"> <div class="container"> <h1>Tutorial Part Four</h1> <p>Using a custom renderer.</p> <div class="row"> <div class="col-md-12"> <h3>Rendering elements</h3> <p>The component has many options to choose from. Look at the way we are now creating the component:</p> <h3><code>js/script.js</code></h3> <p>We group the results by Continent. We use custom renderers to change the way that elements appear in the combo and once they have been selected:</p> <pre><code>$(function() { $('#ms').magicSuggest({ data: 'get_countries.php', valueField: 'idCountry', displayField: 'countryName', groupBy: 'continentName', renderer: function(data){ return '&lt;div class=&quot;country&quot;&gt;' + '&lt;img src=&quot;img/flags/' + data.countryCode.toLowerCase() + '.png&quot; /&gt;' + '&lt;div class=&quot;name&quot;&gt;' + data.countryName + '&lt;/div&gt;' + '&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;' + '&lt;div class=&quot;prop&quot;&gt;' + '&lt;div class=&quot;lbl&quot;&gt;Population : &lt;/div&gt;' + '&lt;div class=&quot;val&quot;&gt;' + data.population + '&lt;/div&gt;' + '&lt;/div&gt;' + '&lt;div class=&quot;prop&quot;&gt;' + '&lt;div class=&quot;lbl&quot;&gt;Capital : &lt;/div&gt;' + '&lt;div class=&quot;val&quot;&gt;' + data.capital + '&lt;/div&gt;' + '&lt;/div&gt;' + '&lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;' + '&lt;/div&gt;'; }, selectionRenderer: function(data){ var img = data.countryCode ? ('&lt;img src=&quot;img/flags/' + data.countryCode.toLowerCase() + '.png&quot; /&gt;') : ''; return img + '&lt;div class=&quot;name&quot;&gt;' + data.countryName + '&lt;/div&gt;'; } }); });</code></pre> <h3><code>css/style.css</code></h3> <p>We make some changes here so that our results look presentable</p> <pre><code>body{ background: #EEE; } .container{ max-width: 500px; border-radius: 5px; background: #FFF; border: 1px solid #CCC; min-height: 400px; margin-top: 50px; } .country{ margin-bottom: 5px; } .country img{ float: left; position: relative; top: 7px; margin-right: 10px; } .country .name{ font-weight: bold; color: #333; } .country .prop{ float: left; width: 50%; } .country .prop .lbl{ font-size: 11px; line-height: 11px; float: left; color: #AAA; margin-left: 25px; margin-right: 5px; } .country .prop .val{ font-size: 11px; line-height: 11px; color: #666; } .ms-sel-item img{ float: left; position: relative; top: 3px; margin-right: 3px; } .ms-sel-item .name{ float: left; }</code></pre> <div class="well"> <h4>Wrapping up...</h4> <a href="tutorial/4.html">View the results</a><br/> <a href="tutorial/4/4.zip">Download the files for the tutorial</a><br/> <br/> <a href="tutorial-5.php.html">Go to part 5</a><br/> </div> </div> </div> </div> </div> <div style="height:200px"></div> </div> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-5470193-5']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </body> </html>