publiclab/spectral-workbench

View on GitHub
app/views/spectrums/_search.html.erb

Summary

Maintainability
Test Coverage
<form id="searchform" action="/spectra/search" method='get' class="form-search">
  <input id="searchform_input" class='search-query input-medium' type='text' name='q' placeholder="Search spectra" value='<%= params[:id] %>'/>
  <button class="btn btn-primary" type='submit'><i class="fa fa-search fa-white"></i></button>
</form>
<script>
  jQuery(document).ready(function() {
    $('#searchform').submit(function(e){ 
      e.preventDefault()
      window.location = '/search/'+$('#searchform_input').val()
    })
    // working off of http://stackoverflow.com/questions/9232748/twitter-bootstrap-typeahead-ajax-example
    $('#searchform_input').typeahead({
      source: function (typeahead, query) {
        return $.post('/search/typeahead/'+query, {}, function (data) {
          return typeahead.process(data)
        })
      },
      items: 15,
      // Autoselect is disabled so that users can enter new tags
      autoselect: false,
      autowidth: false
    })
  })
</script>