Dynamically populating an HTML select element

865 views
Skip to first unread message

emble...@gmail.com

unread,
Jun 2, 2016, 11:02:52 PM6/2/16
to Node-RED
I'd like to have a select element in a Node popup be populated with a dynamic list of tables in my database.  I'm unsure how best to pass that table information into the HTML file of my custom node so that the select element renders properly.

Nicholas O'Leary

unread,
Jun 3, 2016, 3:17:26 AM6/3/16
to Node-RED Mailing List
Hi,

there serial node does this to provide a list of active serial ports to the config dialog.


Nick

On 3 June 2016 at 04:02, <emble...@gmail.com> wrote:
I'd like to have a select element in a Node popup be populated with a dynamic list of tables in my database.  I'm unsure how best to pass that table information into the HTML file of my custom node so that the select element renders properly.

--
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+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

emble...@gmail.com

unread,
Jun 3, 2016, 4:19:06 PM6/3/16
to Node-RED

Thanks for the reply.

I'm not sure how a list of serial ports can help me dynamically populate a dropdown in the HTML file of a custom node.  Lemme add some pictures to help add some more clarity to my scenario:


I'd like to populate the Database Name dropdown with a liste of databases and the Store Name with a list of stores from the currently selected database.  I have the jQuery all setup to do this, I just can't figure out how to pass the database information from my server to this node via pre-rendering or any other means.

Nicholas O'Leary

unread,
Jun 3, 2016, 4:21:28 PM6/3/16
to Node-RED Mailing List
The example I pointed you at is exactly what you want. It demonstrates the UI making a request of the runtime to dynamically get information to update the UI. If you substitute 'list of serial ports' with 'list of databases' then it is what you want.

Nick

--

emble...@gmail.com

unread,
Jun 3, 2016, 7:32:26 PM6/3/16
to Node-RED
Aha!

I was tinkering with the idea of utilizing an Ajax call to get that data.  My concern was security.  Does Node-red have any security middleware or best practices so that only the wiring UI can make a call to endpoints like /serialports?

Nicholas O'Leary

unread,
Jun 3, 2016, 7:37:22 PM6/3/16
to Node-RED Mailing List
If you follow the serial port example, you can see the security model in action:

1. the endpoint is attached to RED.httpAdmin - which means it is subject to the same authentication as the editor
2. the call to RED.auth.needsPermission() returns a middleware that ensures the current user has the necessary permissions to access the resource. The naming scheme for permissions is "<resource>.read" and "<resource>.write".

Nick


On 4 June 2016 at 00:32, <emble...@gmail.com> wrote:
Aha!

I was tinkering with the idea of utilizing an Ajax call to get that data.  My concern was security.  Does Node-red have any security middleware or best practices so that only the wiring UI can make a call to endpoints like /serialports?

--

emble...@gmail.com

unread,
Jun 14, 2016, 8:00:14 PM6/14/16
to Node-RED
Thanks again for this solution.  Works very nicely. :D
Reply all
Reply to author
Forward
0 new messages