<div class="form-row">
<label for="node-input-category"><i class="fa fa-envelope"></i> Category</label>
<select id="node-input-category"></select>
</div> // Load the available categories from the server
$.getJSON('unit-converter/categories', function(data) {
// The response is a json array, containing all the available unit categories
data.sort();
// Allow the user to specify the units via the input message
//$("<option value='message'> **MESSAGE BASED**</option>").appendTo("#node-input-category");
// Show all available categories in the dropdown
for (i = 0; i < data.length; i++) {
var category = data[i];
$("<option value='" + category + "'> " + category.charAt(0).toUpperCase() + category.slice(1) + "</option>").appendTo("#node-input-category");
}
// Set the 'length' as default category at the start, to make sure that the 'unit' dropdowns are filled correctly
if (!node.category) {
node.category = 'length';
}
// When a categorie is already available, make sure it is selected in the dropdown
if (node.category) {
$("#node-input-category").val(node.category);
// Setting the dropdown value from javascript (using val()), won't trigger the change-event automatically
$('#node-input-category').trigger('change');
}
}); // Make all the available types accessible for the node's config screen
RED.httpAdmin.get('/unit-converter/:cmd', /*RED.auth.needsPermission('unitconverter.read'),*/ function(req, res){
var node = RED.nodes.getNode(req.params.id);
if (req.params.cmd === "categories") {
// Return a list of all available categories (mass, length, ...)
res.json(convert().measures());
}
....
}
});--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/38372628-5bf6-4260-97e5-3ef74bc5bfa3%40googlegroups.com.
$.getJSON('unit-converter/categories', function(data)