app/views/keywords/_new.html.haml
= form_tag :action => "add_keyword", :id => what.id do |f|
.input-group
= text_field_tag :keyword, nil, class: "form-control", id: "tokens", placeholder: "Keyword", required: true
%span.input-group-btn
= button_tag(type: 'submit', class: "btn btn-default") do
Save
%span.help-block
Separate keywords by comma.
:javascript
$(document).ready(function() {
$('#tokens').selectize({
delimiter: ',',
persist: false,
valueField: 'name',
labelField: 'name',
searchField: 'name',
options: [],
create: true,
render: {
option: function(item, escape) {
return '<p>' +
escape(item.name) +
'</p>';
}
},
load: function(query, callback) {
console.log("load function");
if (!query.length) return callback();
$.ajax({
url: "#{search_keywords_path}.json",
type: 'GET',
dataType: 'json',
data: {
query: query,
},
error: function(res) {
console.log("error");
console.log(res);
callback();
},
success: function(res) {
console.log("success");
console.log(res);
callback(res.keywords);
}
});
}
});
});