I am using the brilliant selectize.js library to generate an attractive select box with option groups. It is all working but I am stuck at the point that I cannot use the custom renderer from the examples page (Email contacts) http://brianreavis.github.io/selectize.js/ because "item" does not know of the "email" attribute. I know how to do this in javascript, but how could I define the two attributes in static html?
In js, this woulde be
$('#id').selectize({
...
options: [
{ name: "Martin", email: "[email protected]" }
],
....
}
I tried the following:
<select>
<option value="Martin|[email protected]" data-name="Martin" data-email="[email protected]">
Martin
</option>
</select>
But this is not working... Finally the render function taken from the examples:
render: {
item: function(item, escape) {
return '<div>' +
(item.name ? '<span class="name">' + escape(item.name) + '</span>' : '') +
(item.email ? '<span class="email">' + escape(item.email) + '</span>' : '') +
'</div>';
},
option: function(item, escape) {
var label = item.name || item.email;
var caption = item.name ? item.email : null;
return '<div>' +
'<span class="label">' + escape(label) + '</span>' +
(caption ? '<span class="caption">' + escape(caption) + '</span>' : '') +
'</div>';
}
}
I would be thankful for any hints!
Regards, Martin